repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
playwright-crx | github_2023 | ruifigueira | typescript | printSubstring | const printSubstring = (val: string): string => val.replace(/"|\\/g, '\\$&'); | // Format substring but do not enclose in double quote marks. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/bundles/expect/third_party/print.ts#L19-L19 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | isExpand | const isExpand = (expand?: boolean): boolean => expand !== false; | /* eslint-disable eqeqeq */ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/bundles/expect/third_party/spyMatchers.ts#L35-L35 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | getRightAlignedPrinter | const getRightAlignedPrinter = (label: string): PrintLabel => {
// Assume that the label contains a colon.
const index = label.indexOf(':');
const suffix = label.slice(index);
return (string: string, isExpectedCall: boolean) =>
(isExpectedCall
? `->${' '.repeat(Math.max(0, index - 2 - string.length))... | // Given a label, return a function which given a string, | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/bundles/expect/third_party/spyMatchers.ts#L95-L106 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | isLineDiffableArg | const isLineDiffableArg = (expected: unknown, received: unknown): boolean => {
const expectedType = getType(expected);
const receivedType = getType(received);
if (expectedType !== receivedType)
return false;
if (isPrimitive(expected))
return false;
if (
expectedType === 'date' ||
expected... | // Almost redundant with function in jest-matcher-utils, | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/bundles/expect/third_party/spyMatchers.ts#L268-L307 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | printReceivedResults | const printReceivedResults = (
label: string,
expected: unknown,
indexedResults: Array<IndexedResult>,
isOnlyCall: boolean,
iExpectedCall?: number,
) => {
if (indexedResults.length === 0)
return '';
if (isOnlyCall && (iExpectedCall === 0 || iExpectedCall === undefined))
return `${label + printRe... | // Return either empty string or one line per indexed result, | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/bundles/expect/third_party/spyMatchers.ts#L322-L352 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | printSubstring | const printSubstring = (val: string): string => val.replace(/"|\\/g, '\\$&'); | // #region | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/matchers/expect.ts#L78-L78 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | cleanup | const cleanup = () => teardownRunner.runDeferCleanup(context, deadline).then(r => r.status); | // Note that upon hitting deadline, we "run cleanup", but it exits immediately | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/runner/taskRunner.ts#L110-L110 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | resolve | async function resolve(specifier: string, context: { parentURL?: string }, defaultResolve: Function) {
if (context.parentURL && context.parentURL.startsWith('file://')) {
const filename = url.fileURLToPath(context.parentURL);
const resolved = resolveHook(filename, specifier);
if (resolved !== undefined)
... | // Node < 18.6: defaultResolve takes 3 arguments. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/transform/esmLoader.ts#L26-L40 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | load | async function load(moduleUrl: string, context: { format?: string }, defaultLoad: Function) {
// Bail out for wasm, json, etc.
// non-js files have context.format === undefined
if (context.format !== 'commonjs' && context.format !== 'module' && context.format !== undefined)
return defaultLoad(moduleUrl, conte... | // Node < 18.6: defaultLoad takes 3 arguments. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/transform/esmLoader.ts#L44-L73 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | globalPreload | function globalPreload(context: { port: MessagePort }) {
transport = createTransport(context.port);
return `
globalThis.__esmLoaderPortPreV20 = port;
`;
} | // Node.js < 20 | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/transform/esmLoader.ts#L78-L83 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | initialize | function initialize(data: { port: MessagePort }) {
transport = createTransport(data?.port);
} | // Node.js >= 20 | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/transform/esmLoader.ts#L86-L88 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | TestInfoImpl.attach | async attach(name: string, options: { path?: string, body?: string | Buffer, contentType?: string } = {}) {
const step = this._addStep({
title: `attach "${name}"`,
category: 'attach',
});
this._attach(await normalizeAndSaveAttachment(this.outputPath(), name, options), step.stepId);
step.comp... | // ------------ TestInfo methods ------------ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/playwright/src/worker/testInfo.ts#L408-L415 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | doFetch | async function doFetch(event: FetchEvent): Promise<Response> {
// In order to make Accessibility Insights for Web work.
if (event.request.url.startsWith('chrome-extension://'))
return fetch(event.request);
const request = event.request;
const client = await self.clients.get(event.clientId);
// When trac... | // @ts-ignore | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/trace-viewer/src/sw/main.ts#L76-L179 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | SnapshotStorage.addResource | addResource(resource: ResourceSnapshot): void {
resource.request.url = rewriteURLForCustomProtocol(resource.request.url);
this._resources.push(resource);
} | // 100MB per each trace | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/trace-viewer/src/sw/snapshotStorage.ts#L30-L33 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | tagNameToColor | function tagNameToColor(str: string) {
let hash = 0;
for (let i = 0; i < str.length; i++)
hash = str.charCodeAt(i) + ((hash << 8) - hash);
return Math.abs(hash % 6);
} | // hash string to integer in range [0, 6] for color index, to get same color for same tag | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/packages/trace-viewer/src/ui/tag.tsx#L32-L37 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | createSpy | const createSpy = (fn: mock.Mock) => {
const spy = function() { };
spy.calls = {
all() {
return fn.mock.calls.map(args => ({ args }));
},
count() {
return fn.mock.calls.length;
},
};
return spy;
}; | // Given a Jest mock function, return a minimal mock of a spy. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/expect/spyMatchers.test.ts#L23-L36 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | ErrorMessage.constructor | constructor(public message: string) {} | // not extending Error! | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/expect/toThrowMatchers.test.ts#L231-L231 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | normalizedExpires | const normalizedExpires = (cookies: Cookie[]) => cookies.map(c => ({ ...c, expires: Math.floor(c.expires) })); | // Slightly different rounding on chromium win. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/library/browsercontext-add-cookies.spec.ts#L83-L83 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | withResolvers | function withResolvers<T = void>() {
let resolve: (value: T) => void;
const promise = new Promise<T>(f => resolve = f);
return { promise, resolve };
} | // Polyfill for Promise.withResolvers, not available in older Node. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/library/route-web-socket.spec.ts#L30-L34 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | onrequest | async function onrequest(
this: ProxyServer,
req: http.IncomingMessage,
res: http.ServerResponse
) {
debug.request('%s %s HTTP/%s ', req.method, req.url, req.httpVersion);
const socket = req.socket;
// pause the socket during authentication so no data is lost
socket.pause();
try {
const success = await auth... | /**
* HTTP GET/POST/DELETE/PUT, etc. proxy requests.
*/ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L81-L281 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | onclose | function onclose() {
debug.request(
'client socket "close" event, aborting HTTP request to "%s"',
req.url
);
proxyReq.abort();
cleanup();
} | // if the client closes the connection prematurely, | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L259-L266 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | onconnect | async function onconnect(
this: ProxyServer,
req: http.IncomingMessage,
socket: net.Socket,
head: Buffer
) {
debug.request('%s %s HTTP/%s ', req.method, req.url, req.httpVersion);
assert(
!head || 0 == head.length,
'"head" should be empty for proxy requests'
);
let res: http.ServerResponse | null;
let got... | /**
* HTTP CONNECT proxy requests.
*/ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L286-L433 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | ontargetclose | function ontargetclose() {
debug.proxyResponse('proxy target %s "close" event', req.url);
socket.destroy();
} | // define target socket event listeners | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L319-L322 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | onfinish | function onfinish() {
debug.response('response "finish" event');
if (res) {
res.detachSocket(socket);
}
socket.end();
} | // called for the ServerResponse's "finish" event | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L391-L397 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | authenticate | async function authenticate(server: ProxyServer, req: http.IncomingMessage) {
if (typeof server.authenticate === 'function') {
debug.request('authenticating request "%s %s"', req.method, req.url);
return server.authenticate(req);
}
// no `server.authenticate()` function, so just allow the request
return true;
} | /**
* Checks `Proxy-Authorization` request headers. Same logic applied to CONNECT
* requests as well as regular HTTP requests.
*/ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L439-L446 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | requestAuthorization | function requestAuthorization(
req: http.IncomingMessage,
res: http.ServerResponse
) {
// request Basic proxy authorization
debug.response(
'requesting proxy authorization for "%s %s"',
req.method,
req.url
);
// TODO: make "realm" and "type" (Basic) be configurable...
const realm = 'proxy';
const header... | /**
* Sends a "407 Proxy Authentication Required" HTTP response to the `socket`.
*/ | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/tests/third_party/proxy/index.ts#L451-L470 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | createTagNameEngine | const createTagNameEngine = () => ({
// Returns the first element matching given selector in the root's subtree.
query(root: Element, selector: string) {
return root.querySelector(selector);
},
// Returns all elements matching given selector in the root's subtree.
queryAll(root: Element, sele... | // Must be a function that evaluates to a selector engine instance. | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/playwright/utils/generate_types/test/test.ts#L885-L895 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | CrxPlayer._performAction | private async _performAction(browserContext: BrowserContext, actionInContext: PerformAction) {
this._checkStopped();
const innerPerformAction = async (mainFrame: Frame | null, actionInContext: PerformAction, cb: (callMetadata: CallMetadata) => Promise<any>): Promise<void> => {
// we must use the default ... | // "borrowed" from ContextRecorder | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/server/recorder/crxPlayer.ts#L147-L299 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | indexToLineColumn | function indexToLineColumn(code: string, index: number) {
const lines = code.split(/\r?\n/);
let line = 0;
let column = index;
while (line < lines.length && column >= lines[line].length + 1) {
column -= lines[line].length + 1;
line++;
}
return { line: line + 1, column: column + 1 };
} | // function to convert string index to line and column | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/server/recorder/parser.ts#L118-L127 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/child_process.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/chokidar.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/dns.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/net.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/readline.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
playwright-crx | github_2023 | ruifigueira | typescript | noop | function noop() {} | /**
* Copyright (c) Rui Figueira.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in... | https://github.com/ruifigueira/playwright-crx/blob/a84dce9e19e4c064bd53b4d419e9756f06976dbf/src/shims/tls.ts#L17-L17 | a84dce9e19e4c064bd53b4d419e9756f06976dbf |
obsidian-chat-cbt-plugin | github_2023 | clairefro | typescript | ChatCbtPlugin.onunload | onunload() {
console.log('unloading plugin');
} | /** Run when plugin is disabled */ | https://github.com/clairefro/obsidian-chat-cbt-plugin/blob/483a11ecbcc95da3d1e0720a5a1790a6b3a5c33b/src/main.ts#L107-L109 | 483a11ecbcc95da3d1e0720a5a1790a6b3a5c33b |
obsidian-chat-cbt-plugin | github_2023 | clairefro | typescript | system | const system = (lang: string) =>
`You are a Cognitive Behavioral Therapist. Your kind and open approach to CBT allows users to confide in you. You will be given an array of dialogue between the therapist and fictional user you refer to in the second person, and your task is to provide a response as the therapist.
R... | // Largely adopted from this reddit post: From https://www.reddit.com/r/ChatGPTPro/comments/12juous/cbt_therapy_prompt/ | https://github.com/clairefro/obsidian-chat-cbt-plugin/blob/483a11ecbcc95da3d1e0720a5a1790a6b3a5c33b/src/prompts/system.ts#L2-L48 | 483a11ecbcc95da3d1e0720a5a1790a6b3a5c33b |
imersao15 | github_2023 | devfullcycle | typescript | BankAccountsService.create | create(createBankAccountDto: CreateBankAccountDto) {
return this.bankAccountRepo.save(createBankAccountDto);
} | //DTO - Data Transfer Object | https://github.com/devfullcycle/imersao15/blob/a3fb65358790dfb4e2f001b1e1324a6e200c2d04/nestjs/src/bank-accounts/bank-accounts.service.ts#L15-L17 | a3fb65358790dfb4e2f001b1e1324a6e200c2d04 |
imersao15 | github_2023 | devfullcycle | typescript | TransactionsService.constructor | constructor(
@InjectRepository(Transaction)
private transactionRepo: Repository<Transaction>,
@InjectRepository(BankAccount)
private bankAccountRepo: Repository<BankAccount>,
private dataSource: DataSource,
@Inject('KAFKA_SERVICE')
private kafkaService: ClientKafka,
) {} | //Service Layer | https://github.com/devfullcycle/imersao15/blob/a3fb65358790dfb4e2f001b1e1324a6e200c2d04/nestjs/src/transactions/transactions.service.ts#L21-L29 | a3fb65358790dfb4e2f001b1e1324a6e200c2d04 |
ssrx | github_2023 | marbemac | typescript | hono | const hono = (): Middleware<[Context]> => {
return ({ args }) => {
const [context] = args;
return {
request: context.req.raw,
setCookie: cookie => {
context.header('Set-Cookie', cookie.serialize());
},
};
};
}; | // Adapted for hono v4 | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/examples/react-router-kitchen-sink/src/api/auth.ts#L14-L24 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | pushError | function pushError(error: unknown) {
console.error(error);
setErrors(current => [error, ...current]);
} | // function resetError() { | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/examples/solid-router-simple/src/components/DevOverlay.tsx#L22-L25 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | procedureLink | const procedureLink: TRPCLink<T> = () => {
return ({ op }) => {
if (op.type === 'query') {
return observable(observer => {
// @ts-expect-error we don't need to strongly type this
const promise: Promise<unknown> = op.path.split('.').reduce(function (o, key) {
... | /**
* On the server, call the procedure directly rather than making a remote http request.
* Adapted from info in https://github.com/trpc/trpc/issues/3335.
*/ | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/plugin-trpc-react/src/plugin.tsx#L85-L108 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | sleep | const sleep = (n = 2000) => new Promise(r => setTimeout(r, n)); | /*!
* Portions of this code are adapted from nextjs.
*
* MIT License, Copyright (c) 2023 Vercel, Inc.
* https://github.com/vercel/next.js/blob/canary/packages/next/src/server/stream-utils/node-web-streams-helper.ts
*/ | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/streaming/src/stream-utils.ts#L9-L9 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | useSubscription | function useSubscription<TPath extends keyof TSubscriptions & string>(
pathAndInput: [path: TPath, ...args: inferHandlerInput<TSubscriptions[TPath]>],
opts: UseTRPCSubscriptionOptions<
inferObservableValue<inferProcedureOutput<TSubscriptions[TPath]>>,
inferProcedureClientError<TSubscriptions[TPath]>... | /**
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
* **Experimental.** API might change without major version bump
* ⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠... | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/trpc-react-query/src/createHooksInternal.tsx#L256-L298 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | Config.basePath | set basePath(val: string) {
// strip leading and trailing slashes
let bp = val ? `/${val.replace(/^\/+|\/+$/g, '')}` : '';
// if basePath is root /, set it to empty string
bp = bp === '/' ? '' : bp;
this.#basePath = bp;
} | /**
* Normalize basePath when we set it. Vite sometimes adds slash at the end turning /foo into /foo/, or //foo etc.
* We want to make sure basePath is always normalized to /foo.
*/ | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/vite/src/config.ts#L139-L147 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | Manifest.getAssets | public async getAssets(url: string) {
// const routeMatches = this.router.getMatchedRoutes(url);
/**
* @TODO scope assets down to the matched route during dev
*/
if (this.config.isDev) {
return this.#getAssetsDev([]);
}
throw new Error('not implemented');
} | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/vite/src/ssr-manifest.ts#L70-L81 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | isAbsoluteRoute | const isAbsoluteRoute = (routePath?: string) => {
if (!routePath) return false;
return routePath.startsWith('/') ? true : false;
}; | /**
* --------------
* Internal below
* --------------
*/ | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/vite/src/helpers/routes.ts#L342-L346 | c0a17bbd659de541257179e5aeba45829e33421e |
ssrx | github_2023 | marbemac | typescript | getModuleBySsrReference | const getModuleBySsrReference = async (vite: ViteDevServer, mod: unknown, moduleUrlAllowList?: Set<string>) => {
for (const value of vite.moduleGraph.idToModuleMap.values()) {
// only consider modules that are in the allow list
if (!value.id || (moduleUrlAllowList && !moduleUrlAllowList.has(value.url))) conti... | /**
* This helper attempts to locate a module in the Vite module graph by reference.
*/ | https://github.com/marbemac/ssrx/blob/c0a17bbd659de541257179e5aeba45829e33421e/packages/vite/src/helpers/routes.ts#L471-L484 | c0a17bbd659de541257179e5aeba45829e33421e |
myanmar-software-engineers.github.io | github_2023 | myanmar-software-engineers | typescript | Contact | const Contact = () => {
return (
<div className=" w-full h-auto items-center flex-wrap flex-col flex gap-4 p-[1rem] ">
<div className=" flex justify-center p-[1rem] bg-[#1a1b27] text-[#6899eb] border rounded w-full items-center ">
<p>This developer is too lazy to descripe himself!</p>
</div>
... | /* eslint-disable @next/next/no-img-element */ | https://github.com/myanmar-software-engineers/myanmar-software-engineers.github.io/blob/63617790c178dbd7d797acc6ac630140199b696a/src/components/Contributors/Vince/Contact.tsx#L3-L43 | 63617790c178dbd7d797acc6ac630140199b696a |
aws-reference-architecture-pulumi | github_2023 | pinecone-io | typescript | calculateExponentialBackoff | const calculateExponentialBackoff = (retryCount: number): number => {
const baseDelay = 1000; // 1 second
return baseDelay * Math.pow(2, retryCount);
}; | // Helper function to calculate exponential backoff | https://github.com/pinecone-io/aws-reference-architecture-pulumi/blob/452cafa72bffba7947a0b1a135a344aa68fe0b04/emu/src/index.ts#L53-L56 | 452cafa72bffba7947a0b1a135a344aa68fe0b04 |
aws-reference-architecture-pulumi | github_2023 | pinecone-io | typescript | deleteMessageFromQueue | const deleteMessageFromQueue = async (receiptHandle: string): Promise<void> => {
const deleteParams = {
QueueUrl: queueURL,
ReceiptHandle: receiptHandle,
};
const command = new DeleteMessageCommand(deleteParams);
await client.send(command);
logger.info({
message: `Deleted message with receipt hand... | // Helper function to delete a message from the SQS queue | https://github.com/pinecone-io/aws-reference-architecture-pulumi/blob/452cafa72bffba7947a0b1a135a344aa68fe0b04/emu/src/index.ts#L59-L72 | 452cafa72bffba7947a0b1a135a344aa68fe0b04 |
aws-reference-architecture-pulumi | github_2023 | pinecone-io | typescript | clearThreadPool | const clearThreadPool = async () => {
await Promise.all(
threadPool.map(async (worker) => {
if (worker.threadId) {
await worker.terminate();
}
}),
);
}; | // eslint-disable-next-line @typescript-eslint/no-unused-vars | https://github.com/pinecone-io/aws-reference-architecture-pulumi/blob/452cafa72bffba7947a0b1a135a344aa68fe0b04/emu/src/orchestrator.ts#L40-L48 | 452cafa72bffba7947a0b1a135a344aa68fe0b04 |
aws-reference-architecture-pulumi | github_2023 | pinecone-io | typescript | getSizeOfRecord | function getSizeOfRecord<T extends RecordMetadata>(
record: PineconeRecord<T>,
): number {
const recordString = JSON.stringify(record);
const recordSize = Buffer.byteLength(recordString, "utf8");
return recordSize;
} | // Given a PineconeRecord, get the size of the record in bytes | https://github.com/pinecone-io/aws-reference-architecture-pulumi/blob/452cafa72bffba7947a0b1a135a344aa68fe0b04/emu/src/orchestrator.ts#L94-L100 | 452cafa72bffba7947a0b1a135a344aa68fe0b04 |
aws-reference-architecture-pulumi | github_2023 | pinecone-io | typescript | getPool | function getPool() {
if (pool) return pool;
pool = new Pool({
host: process.env.POSTGRES_DB_HOST,
port: Number(process.env.POSTGRES_DB_PORT || "5432"),
database: process.env.POSTGRES_DB_NAME,
user: process.env.POSTGRES_DB_USER,
password: process.env.POSTGRES_DB_PASSWORD,... | // Initialize the pool | https://github.com/pinecone-io/aws-reference-architecture-pulumi/blob/452cafa72bffba7947a0b1a135a344aa68fe0b04/semantic-search-postgres/src/utils/db.ts#L5-L20 | 452cafa72bffba7947a0b1a135a344aa68fe0b04 |
transporter | github_2023 | daniel-nagy | typescript | BrowserClient.fetch | async fetch(body: StructuredCloneable.t): Promise<StructuredCloneable.t> {
const messageSink = await getMessageSink(this.target);
const messageSource = getMessageSource(this.target);
const request = Request.t({ address: this.serverAddress, body });
const response = Observable.fromEvent<MessageEvent>(
... | /**
* Makes a request to the server. Returns a promise that resolves with the
* response from the server.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserClient.ts#L68-L87 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserServer.state | get state() {
return this.#state.getValue();
} | /**
* Returns the current state of the server.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserServer.ts#L85-L87 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserServer.stop | stop() {
this.#state.next(State.Stopped);
this.#state.complete();
AddressBook.release(ADDRESS_SPACE, this.address);
} | /**
* Stops the server. Once stopped the server will no longer receive requests.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserServer.ts#L106-L110 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocketServer.state | get state() {
return this.#state.getValue();
} | /**
* Returns the current state of the socket server.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocketServer.ts#L101-L103 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocketServer.stop | stop() {
this.#state.next(State.Stopped);
this.#connect.complete();
this.#state.complete();
this.#clients.forEach((client) => client.send(Message.Disconnect()));
AddressBook.release(ADDRESS_SPACE, this.address);
} | /**
* Stops the server. A disconnect message will be sent to all connected
* clients.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocketServer.ts#L123-L129 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | createScript | async function createScript(fileName: string, src: string): Promise<boolean> {
return fetch("/create_script", {
body: JSON.stringify({ fileName, src: src }),
headers: { "Content-Type": "text/json" },
method: "POST"
}).then((result) => result.ok);
} | /**
* Calls out to the dev server to create a script with the given filename.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/Test.ts#L121-L127 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | transpile | function transpile(src: string): Promise<string> {
const polyfills = /* js */ `
Symbol.asyncDispose ??= Symbol("Symbol.asyncDispose");
Symbol.dispose ??= Symbol("Symbol.dispose");
`;
return fetch("/transpile", {
body: /* js */ `
import "data:text/javascript;charset=utf-8;base64,${btoa(polyfills... | /**
* Calls out to the dev server to transpile a script using TypeScript.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/Test.ts#L132-L146 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | transpileHtml | function transpileHtml(html: string): Promise<string> {
const container = Object.assign(document.createElement("div"), {
innerHTML: html
});
return Promise.all(
Array.from(container.querySelectorAll(`script[data-transpile]`)).map(
(script) =>
transpile(script.textContent!).then((text) => {
... | /**
* Given an HTML document, transpiles the content of all script tags with the
* `data-transpile` attribute and returns the new document.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/Test.ts#L152-L165 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocket.state | get state() {
return this.#state.getValue();
} | /**
* Returns the current state of the socket.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocket/BrowserSocket.ts#L167-L169 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocket.close | close() {
this.#close();
} | /**
* Closes the socket causing its state to transition to closing.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocket/BrowserSocket.ts#L208-L210 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocket.ping | ping(timeout: number = 2000): Promise<void> {
const ping = Message.Ping();
this.#send.next(ping);
return this.#receive.pipe(
Observable.filter(
(message) =>
Message.isType(message, Message.Type.Pong) && message.id === ping.id
),
Observable.timeout(timeout),
Observa... | /**
* Sends a ping to a connected socket and waits for a pong to be sent back.
* The default timeout for a pong is `2000` milliseconds or 2 seconds.
*
* @returns A promise that resolves when a pong is received or rejects if a
* pong is not received in the allotted time.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocket/BrowserSocket.ts#L219-L232 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | BrowserSocket.send | send(message: StructuredCloneable.t) {
if (this.state.type === State.Type.Closing && !Message.isMessage(message))
return;
this.#send.next(message);
} | /**
* Sends data through the socket.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/browser/src/BrowserSocket/BrowserSocket.ts#L237-L242 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.add | add(func: JsFunction.t, args: SuperJson.t[], value: unknown) {
const cache = this.#state.get(func) ?? new Map();
this.#state.set(
func,
cache.set(Json.serialize(SuperJson.toJson(args)), value)
);
} | /**
* Add the return value of a function call to the cache.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L49-L56 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.get | get<Args extends SuperJson.t[], Return>(
func: (...args: Args) => Return,
args: Args
): Return | NotFound {
if (!this.#state.has(func)) return NotFound;
const funcCache = this.#state.get(func)!;
const argsKey = Json.serialize(SuperJson.toJson(args));
return funcCache.has(argsKey)
? (fu... | /**
* Get the return value of a function call from the cache. Returns `NotFound`
* if the value does not exist in the cache.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L62-L74 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.has | has(func: JsFunction.t, args?: SuperJson.t[]): boolean {
if (!args) return this.#state.has(func);
return (
this.#state.get(func)?.has(Json.serialize(SuperJson.toJson(args))) ??
false
);
} | /**
* Checks to see if a value exists in the cache for a given function and
* arguments.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L80-L87 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.memo | memo<Args extends SuperJson.t[], Return>(
func: (...args: Args) => Return
): (...args: Args) => Return {
return (...args: Args) => {
if (!this.has(func, args)) this.add(func, args, func(...args));
return this.get(func, args) as Return;
};
} | /**
* Wraps a function so that calling the wrapped function will automatically
* read and write from the cache.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L93-L100 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.remove | remove(func: JsFunction.t, args?: SuperJson.t[]): boolean {
if (!args) return this.#state.delete(func);
return (
this.#state.get(func)?.delete(Json.serialize(SuperJson.toJson(args))) ??
false
);
} | /**
* Remove a value from the cache. Returns `true` if the value was found and
* removed.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L106-L113 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Cache.update | update<Args extends SuperJson.t[], Return>(
func: (...args: Args) => Return,
args: Args,
callback: (value: Return) => Return
): void {
if (this.has(func, args))
this.add(func, args, callback(this.get(func, args) as Return));
} | /**
* Allows updating a value in the cache so that future calls return the new
* value.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Cache.ts#L119-L126 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | ClientAgent.createProxy | createProxy(path: string[] = []) {
const children: Record<string, unknown> = {};
const meta: Metadata.t = {
clientAgentId: this.id,
objectPath: path
};
const proxy = new Js.Proxy(() => {}, {
apply: (_target, _thisArg, input) => {
const message = Message.CallFunction({
... | /**
* Creates a `Proxy` object for a remote resource. This creates the illusion
* that the resource is local, allowing familiar procedural programming to be
* used to interface with the remote resource. However, because the resource
* is in fact remote, all function calls will return a promise.
*
* Fo... | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/ClientAgent.ts#L130-L194 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | EncodedProxy | const EncodedProxy = (address: string): EncodedProxy => ({
type: Type.Proxy,
address
}); | /**
* Encodes a proxy such that a client can discover the address of the proxy when
* decoding a message.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Codec.ts#L73-L76 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Fiber.terminate | terminate() {
this.#state.next(State.Terminated);
this.#state.complete();
table.delete(this.id);
} | /**
* Terminates the fiber. The fiber's state will transition to `Terminated` and
* then complete.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Fiber.ts#L48-L52 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Injector.add | add<Value>(tag: Tag<Value>, value: Value): Injector {
this.#state.set(tag, value);
return this;
} | /**
* Adds a value to the container using a tag.
*
* @example
*
* type Session = { clientId: string; }
* const Session = Injector.Tag<Session>();
* const injector = Injector.empty();
* injector.add(Session, { clientId: "Client:1" })
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Injector.ts#L61-L64 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Injector.get | get(tag: Tag<unknown>) {
return this.#state.get(tag);
} | /**
* Gets a value from the container using a tag.
*
* @example
*
* injector.get(Session); // { clientId: "Client:1" }
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Injector.ts#L73-L75 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | ClientSession.createProxy | createProxy(): Value extends object ? Proxy.t<Value> : JsObject.Empty {
return this.#clientAgent.createProxy() as Value extends object
? Proxy.t<Value>
: JsObject.Empty;
} | // TODO: Force value to extend object. | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Session.ts#L227-L231 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Subject.asObservable | asObservable(): Observable.t<T> {
return Observable.from(this);
} | /**
* Transforms the subject into a hot observable.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Subject.ts#L25-L27 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Subprotocol | const Subprotocol = <
const Type,
const Connection extends ConnectionMode,
const Operation extends OperationMode,
const Transmission extends TransmissionMode
>({
connectionMode,
dataType: _dataType,
operationMode,
transmissionMode
}: {
connectionMode: Connection;
dataType: DataType<Type>;
operatio... | /**
* The Transporter protocol is type agnostic. In order to provide type-safety a
* subprotocol is required. The subprotocol restricts what types may be included
* in function IO. For example, if the data type of a subprotocol is JSON then
* only JSON data types may be input or output from remote functions.
*
* ... | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Subprotocol.ts#L95-L116 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Supervisor.observe | observe(task: Task) {
if (this.state === Fiber.State.Terminated)
throw new TerminatedError(
"Refusing to add task to terminated supervisor."
);
if (this.tasks.has(task.id))
throw new UniqueTaskIdError(
`A task with id "${task.id}" already exists.`
);
this.tasks.set(... | /**
* Starts observing a new task. If an observed task terminates it will no
* longer be observed.
*
* @throws {TerminatedError} If the supervisor is terminated.
*
* @throws {UniqueTaskIdError} If the supervisor is already observing a task with the same id.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Supervisor.ts#L40-L59 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Supervisor.terminate | terminate() {
this.taskCount
.pipe(Observable.filter((count) => count === 0))
.subscribe(() => queueMicrotask(() => this.#taskCount.complete()));
this.tasks.forEach((task) => task.terminate());
super.terminate();
} | /**
* Terminates all tasks and then terminates the supervisor.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Supervisor.ts#L64-L72 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | v4Fallback | function v4Fallback(): string {
const a = hex(48);
const b = hex(12);
const c = `${hex(31)}${hex(31)}`;
return `${a.slice(0, 8)}-${a.slice(8)}-4${b}-a${c.slice(0, 3)}-${c.slice(
3,
15
)}`;
} | /**
* Generates a v4 UUID. This implementation generates exactly 122 bits of random
* data and concatenates the version and variant.
*
* @see https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-version-4
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/UUID.ts#L15-L24 | f13d713cd8339f2f4493607a811cd09a043eef00 |
transporter | github_2023 | daniel-nagy | typescript | Observable.subscribe | subscribe(observerOrNext?: Observer<T> | ((value: T) => void)): Subscription {
const cleanUp = this.#subscribe(toObserver(observerOrNext));
return {
unsubscribe() {
cleanUp();
}
};
} | /**
* Start receiving values from this observable as they are emitted.
*/ | https://github.com/daniel-nagy/transporter/blob/f13d713cd8339f2f4493607a811cd09a043eef00/packages/core/src/Observable/Observable.ts#L230-L238 | f13d713cd8339f2f4493607a811cd09a043eef00 |
XAgent | github_2023 | OpenBMB | typescript | start | const start = async () => {
const app = createApp(App)
app.directive('react', (el, binding) => {
useReactInsideVue(binding.value, el)
});
setupStore(app)
setupRouter(app)
setupRouteGuard(router)
setupHighlightDirective(app)
app.use(JsonViewer)
app.use(VueViewer);
for (const [key, component] o... | // Import JsonViewer as a Vue.js plugin | https://github.com/OpenBMB/XAgent/blob/3619c25855f878481ddb893709c1e30d76aff794/XAgentWeb/src/main.ts#L21-L44 | 3619c25855f878481ddb893709c1e30d76aff794 |
XAgent | github_2023 | OpenBMB | typescript | throttle | const throttle = (fn: Function, delay: number) => {
let prev = Date.now();
let context: any = this;
return (...args: any) => {
let now = Date.now();
if (now - prev >= delay) {
fn.call(context, ...args);
prev = Date.now();
}
};
} | // const throttle = (fn: Function, delay: number) => { | https://github.com/OpenBMB/XAgent/blob/3619c25855f878481ddb893709c1e30d76aff794/XAgentWeb/src/utils/throttle.ts#L16-L26 | 3619c25855f878481ddb893709c1e30d76aff794 |
supersplat | github_2023 | playcanvas | typescript | sorter | const sorter = (a: File, b: File) => {
const avalue = a.name?.match(regex)?.[2];
const bvalue = b.name?.match(regex)?.[2];
return (avalue && bvalue) ? parseInt(avalue, 10) - parseInt(bvalue, 10) : 0;
}; | // sort frames by trailing number, if it exists | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/animation.ts#L17-L21 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | firstRender | const firstRender = (splat: Splat) => {
return new Promise<void>((resolve) => {
splat.entity.gsplat.instance.sorter.on('updated', (count) => {
resolve();
});
});
}; | // resolves on first render frame | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/animation.ts#L29-L35 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | deserializeFromSSplat | const deserializeFromSSplat = (data: ArrayBufferLike) => {
const totalSplats = data.byteLength / 32;
const dataView = new DataView(data);
const storage_x = new Float32Array(totalSplats);
const storage_y = new Float32Array(totalSplats);
const storage_z = new Float32Array(totalSplats);
const stor... | // ideally this function would stream data directly into GSplatData buffers. | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/asset-loader.ts#L18-L85 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | calcForwardVec | const calcForwardVec = (result: Vec3, azim: number, elev: number) => {
const ex = elev * math.DEG_TO_RAD;
const ey = azim * math.DEG_TO_RAD;
const s1 = Math.sin(-ex);
const c1 = Math.cos(-ex);
const s2 = Math.sin(-ey);
const c2 = Math.cos(-ey);
result.set(-c1 * s2, s1, c1 * c2);
}; | // calculate the forward vector given azimuth and elevation | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L34-L42 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | mod | const mod = (n: number, m: number) => ((n % m) + m) % m; | // modulo dealing with negative numbers | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L54-L54 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.ortho | set ortho(value: boolean) {
if (value !== this.ortho) {
this.entity.camera.projection = value ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE;
this.scene.events.fire('camera.ortho', value);
}
} | // ortho | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L88-L93 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.fov | set fov(value: number) {
this.entity.camera.fov = value;
} | // fov | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L100-L102 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.tonemapping | set tonemapping(value: string) {
const mapping: Record<string, number> = {
none: TONEMAP_NONE,
linear: TONEMAP_LINEAR,
neutral: TONEMAP_NEUTRAL,
aces: TONEMAP_ACES,
aces2: TONEMAP_ACES2,
filmic: TONEMAP_FILMIC,
hejl: TONEMAP_HEJ... | // tonemapping | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L109-L126 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.near | set near(value: number) {
this.entity.camera.nearClip = value;
} | // near clip | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L142-L144 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.far | set far(value: number) {
this.entity.camera.farClip = value;
} | // far clip | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L151-L153 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.focalPoint | get focalPoint() {
const t = this.focalPointTween.target;
return new Vec3(t.x, t.y, t.z);
} | // focal point | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L160-L163 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.azimElev | get azimElev() {
return this.azimElevTween.target;
} | // azimuth, elevation | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L166-L168 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.worldToScreen | worldToScreen(world: Vec3, screen: Vec3) {
this.entity.camera.worldToScreen(world, screen);
} | // convert world to screen coordinate | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L226-L228 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
supersplat | github_2023 | playcanvas | typescript | Camera.onBoundChanged | onBoundChanged(bound: BoundingBox) {
const prevDistance = this.distanceTween.value.distance * this.sceneRadius;
this.sceneRadius = Math.max(1e-03, bound.halfExtents.length());
this.setDistance(prevDistance / this.sceneRadius, 0);
} | // also update the existing camera distance to maintain the current view | https://github.com/playcanvas/supersplat/blob/ae1a7968fa730954a97c67a97678fdddf17c3ef3/src/camera.ts#L339-L343 | ae1a7968fa730954a97c67a97678fdddf17c3ef3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.