@snap/valdi 1.0.7 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/BUILD.bazel.template +16 -1
  2. package/.bootstrap/modules/polyglot_bridge_module/web/Calculator.ts +11 -0
  3. package/.bootstrap/modules/polyglot_bridge_module/web/tsconfig.json +16 -0
  4. package/.bootstrap/modules/polyglot_view_module/BUILD.bazel.template +75 -0
  5. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeView.kt.template +41 -0
  6. package/.bootstrap/modules/polyglot_view_module/android/PolyglotNativeViewAttributesBinder.kt.template +17 -0
  7. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.h +8 -0
  8. package/.bootstrap/modules/polyglot_view_module/ios/SCPolyglotView.m +23 -0
  9. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.h +8 -0
  10. package/.bootstrap/modules/polyglot_view_module/macos/SCPolyglotView.m +23 -0
  11. package/.bootstrap/modules/polyglot_view_module/src/PolyglotCustomView.tsx.template +23 -0
  12. package/.bootstrap/modules/polyglot_view_module/web/PolyglotWeb.ts.template +30 -0
  13. package/.bootstrap/modules/polyglot_view_module/web/tsconfig.json +16 -0
  14. package/.metadata/AGENTS.md.template +8 -274
  15. package/.metadata/skill-reference.tsx.template +8 -0
  16. package/.metadata/skill-tests-BUILD.bazel.template +21 -0
  17. package/.metadata/skill-tests-README.md.template +17 -0
  18. package/.metadata/skill.md.template +27 -0
  19. package/README.md +12 -3
  20. package/bundled-skills/CONTRIBUTING_SKILLS.md +74 -0
  21. package/bundled-skills/registry.json +21 -0
  22. package/bundled-skills/skills/valdi-android/skill.md +89 -0
  23. package/bundled-skills/skills/valdi-async/skill.md +246 -0
  24. package/bundled-skills/skills/valdi-async/tests/BUILD.bazel +19 -0
  25. package/bundled-skills/skills/valdi-async/tests/README.md +25 -0
  26. package/bundled-skills/skills/valdi-async/tests/src/reference.tsx +210 -0
  27. package/bundled-skills/skills/valdi-async/tests/tsconfig.json +1 -0
  28. package/bundled-skills/skills/valdi-bazel/skill.md +141 -0
  29. package/bundled-skills/skills/valdi-compiler/skill.md +108 -0
  30. package/bundled-skills/skills/valdi-component-tests/skill.md +430 -0
  31. package/bundled-skills/skills/valdi-component-tests/tests/BUILD.bazel +24 -0
  32. package/bundled-skills/skills/valdi-component-tests/tests/README.md +35 -0
  33. package/bundled-skills/skills/valdi-component-tests/tests/src/ProfileCard.tsx +38 -0
  34. package/bundled-skills/skills/valdi-component-tests/tests/test/ProfileCardTest.spec.tsx +107 -0
  35. package/bundled-skills/skills/valdi-component-tests/tests/tsconfig.json +1 -0
  36. package/bundled-skills/skills/valdi-cpp-runtime/skill.md +103 -0
  37. package/bundled-skills/skills/valdi-custom-view/skill.md +64 -0
  38. package/bundled-skills/skills/valdi-inspect/skill.md +199 -0
  39. package/bundled-skills/skills/valdi-ios/skill.md +93 -0
  40. package/bundled-skills/skills/valdi-migrate/skill.md +175 -0
  41. package/bundled-skills/skills/valdi-migrate/tests/BUILD.bazel +23 -0
  42. package/bundled-skills/skills/valdi-migrate/tests/README.md +70 -0
  43. package/bundled-skills/skills/valdi-migrate/tests/check_antipatterns.py +89 -0
  44. package/bundled-skills/skills/valdi-migrate/tests/compose_example.kt +94 -0
  45. package/bundled-skills/skills/valdi-migrate/tests/flutter_example.dart +129 -0
  46. package/bundled-skills/skills/valdi-migrate/tests/react_example.tsx +98 -0
  47. package/bundled-skills/skills/valdi-migrate/tests/src/expected_valdi.tsx +267 -0
  48. package/bundled-skills/skills/valdi-migrate/tests/tsconfig.json +3 -0
  49. package/bundled-skills/skills/valdi-overview/skill.md +63 -0
  50. package/bundled-skills/skills/valdi-perf/skill.md +197 -0
  51. package/bundled-skills/skills/valdi-perf/tests/BUILD.bazel +19 -0
  52. package/bundled-skills/skills/valdi-perf/tests/README.md +26 -0
  53. package/bundled-skills/skills/valdi-perf/tests/src/reference.tsx +202 -0
  54. package/bundled-skills/skills/valdi-perf/tests/tsconfig.json +1 -0
  55. package/bundled-skills/skills/valdi-polyglot-module/skill.md +124 -0
  56. package/bundled-skills/skills/valdi-profile/skill.md +126 -0
  57. package/bundled-skills/skills/valdi-setup/skill.md +129 -0
  58. package/bundled-skills/skills/valdi-testing/skill.md +65 -0
  59. package/bundled-skills/skills/valdi-tsx/skill.md +385 -0
  60. package/bundled-skills/skills/valdi-tsx/tests/BUILD.bazel +19 -0
  61. package/bundled-skills/skills/valdi-tsx/tests/README.md +29 -0
  62. package/bundled-skills/skills/valdi-tsx/tests/src/reference.tsx +173 -0
  63. package/bundled-skills/skills/valdi-tsx/tests/tsconfig.json +1 -0
  64. package/dist/commands/bootstrap.js +0 -7
  65. package/dist/commands/inspect.js +16 -0
  66. package/dist/commands/inspect_commands/contexts.js +55 -0
  67. package/dist/commands/inspect_commands/devices.js +53 -0
  68. package/dist/commands/inspect_commands/heap.js +59 -0
  69. package/dist/commands/inspect_commands/select.js +43 -0
  70. package/dist/commands/inspect_commands/snapshot.js +64 -0
  71. package/dist/commands/inspect_commands/status.js +68 -0
  72. package/dist/commands/inspect_commands/tree.js +86 -0
  73. package/dist/commands/newModule.js +10 -14
  74. package/dist/commands/profile.js +16 -0
  75. package/dist/commands/profile_commands/capture.js +106 -0
  76. package/dist/commands/skills.js +16 -0
  77. package/dist/commands/skills_commands/create.js +125 -0
  78. package/dist/commands/skills_commands/install.js +96 -0
  79. package/dist/commands/skills_commands/list.js +83 -0
  80. package/dist/commands/skills_commands/remove.js +41 -0
  81. package/dist/commands/skills_commands/update.js +59 -0
  82. package/dist/core/constants.js +0 -1
  83. package/dist/core/packageFiles.spec.js +29 -0
  84. package/dist/setup/versions.js +1 -1
  85. package/dist/utils/daemonClient.js +342 -0
  86. package/dist/utils/hermesClient.js +252 -0
  87. package/dist/utils/skillsAdapters.js +140 -0
  88. package/dist/utils/skillsRegistry.js +40 -0
  89. package/dist/utils/stringUtils.spec.js +1 -1
  90. package/package.json +20 -5
  91. package/.bazelignore +0 -2
  92. package/.bootstrap/modules/cpp_bridge_module/BUILD.bazel.template +0 -21
  93. package/.bootstrap/modules/cpp_bridge_module/cpp/CalculatorModuleFactory.cpp.template +0 -28
  94. package/.bootstrap/modules/ios_android_bridge_module/src/Calculator.d.ts +0 -4
  95. package/.bootstrap/modules/ios_android_view_module/BUILD.bazel.template +0 -41
  96. package/.bootstrap/modules/ios_android_view_module/android/CircleView.kt.template +0 -42
  97. package/.bootstrap/modules/ios_android_view_module/android/CircleViewAttributesBinder.kt.template +0 -60
  98. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.h +0 -6
  99. package/.bootstrap/modules/ios_android_view_module/ios/SCCCircleView.m +0 -82
  100. package/.bootstrap/modules/ios_android_view_module/src/Circle.tsx.template +0 -15
  101. package/.config/copyconfig.json +0 -10
  102. package/.editorconfig +0 -21
  103. package/.eslintignore +0 -1
  104. package/.eslintrc.js +0 -72
  105. package/.github/README.md +0 -164
  106. package/.metadata/.cursorrules.template +0 -60
  107. package/.prettierignore +0 -2
  108. package/.prettierrc.json +0 -7
  109. package/LINUX_COMPATIBILITY.md +0 -248
  110. package/prettier.config.js +0 -4
  111. package/scripts/sync-agents-md.sh +0 -44
  112. package/scripts/update-agents-templates.ts +0 -170
  113. package/spec/support/jasmine.json +0 -6
  114. package/src/commands/bootstrap.ts +0 -410
  115. package/src/commands/build.ts +0 -89
  116. package/src/commands/devSetup.ts +0 -17
  117. package/src/commands/doctor.ts +0 -1832
  118. package/src/commands/export.ts +0 -131
  119. package/src/commands/hotreload.ts +0 -108
  120. package/src/commands/install.ts +0 -93
  121. package/src/commands/lint.ts +0 -15
  122. package/src/commands/lint_commands/lintCheck.ts +0 -53
  123. package/src/commands/lint_commands/lintFormat.ts +0 -49
  124. package/src/commands/log.ts +0 -108
  125. package/src/commands/newModule.ts +0 -286
  126. package/src/commands/package.ts +0 -102
  127. package/src/commands/projectsync.ts +0 -488
  128. package/src/commands/test.ts +0 -68
  129. package/src/core/constants.ts +0 -98
  130. package/src/core/errors.ts +0 -10
  131. package/src/index.ts +0 -27
  132. package/src/setup/DevSetupHelper.ts +0 -290
  133. package/src/setup/linuxSetup.ts +0 -261
  134. package/src/setup/macOSSetup.ts +0 -156
  135. package/src/setup/setupEntryPoint.ts +0 -64
  136. package/src/setup/versions.ts +0 -8
  137. package/src/utils/ArgumentsResolver.ts +0 -23
  138. package/src/utils/BazelClient.ts +0 -285
  139. package/src/utils/Digraph.ts +0 -81
  140. package/src/utils/LoadingIndicator.ts +0 -43
  141. package/src/utils/applicationUtils.ts +0 -276
  142. package/src/utils/buildInfo.ts +0 -99
  143. package/src/utils/byString.ts +0 -3
  144. package/src/utils/cliUtils.ts +0 -112
  145. package/src/utils/copyBootstrapFiles.ts +0 -30
  146. package/src/utils/deviceUtils.ts +0 -76
  147. package/src/utils/errorUtils.ts +0 -63
  148. package/src/utils/fileUtils.ts +0 -257
  149. package/src/utils/githubUtils.ts +0 -102
  150. package/src/utils/jsonUtils.ts +0 -30
  151. package/src/utils/lintUtils.ts +0 -190
  152. package/src/utils/linuxDistro.spec.ts +0 -219
  153. package/src/utils/linuxDistro.ts +0 -326
  154. package/src/utils/logUtils.ts +0 -9
  155. package/src/utils/pathUtils.ts +0 -12
  156. package/src/utils/stringUtils.spec.ts +0 -95
  157. package/src/utils/stringUtils.ts +0 -103
  158. package/src/utils/tempDir.ts +0 -24
  159. package/src/utils/zipUtils.ts +0 -14
  160. package/test/ValdiSmokeTest.ts +0 -279
  161. package/test/helpers/AsyncHelpers.ts +0 -113
  162. package/test/helpers/CommandHelpers.ts +0 -37
  163. package/test/helpers/ProjectHelpers.ts +0 -153
  164. package/test/helpers/StreamHelpers.ts +0 -37
  165. package/test/helpers/TypeScriptClient.ts +0 -217
  166. package/tsconfig.dist.json +0 -8
  167. package/tsconfig.json +0 -42
  168. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/android/CalculatorModuleFactory.kt.template +0 -0
  169. /package/.bootstrap/modules/{ios_android_bridge_module → polyglot_bridge_module}/ios/SCCCalculatorModuleFactory.m.template +0 -0
  170. /package/.bootstrap/modules/{cpp_bridge_module → polyglot_bridge_module}/src/Calculator.d.ts +0 -0
@@ -1,153 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import { mkdir, readFile, writeFile } from 'fs/promises';
3
- import path from 'path';
4
- import { eachLine } from './StreamHelpers';
5
- import type { FilePosition, TSServerClient } from './TypeScriptClient';
6
- import { lineAndOffset } from './TypeScriptClient';
7
-
8
- type FileUpdater = (contents: Buffer) => Promise<Buffer>;
9
-
10
- export interface ProjectConfig {
11
- rootPath: string;
12
- name: string;
13
- findFile: (fileName: string, withinModule?: string) => Promise<string>;
14
- updateFile: (fileName: string, withinModule: string | undefined, change: FileUpdater) => Promise<void>;
15
- createFile: (
16
- fileName: string,
17
- withinModule: string | undefined,
18
- source: Parameters<typeof writeFile>[1],
19
- ) => Promise<string>;
20
- }
21
-
22
- interface TaskContext {
23
- project: ProjectConfig;
24
- client: TSServerClient;
25
- }
26
-
27
- export function createProject(name: string, rootPath: string): ProjectConfig {
28
- const findFile: ProjectConfig['findFile'] = (fileName, withinModule) => {
29
- return new Promise((resolve, reject) => {
30
- const buffers: Buffer[] = [];
31
-
32
- const errorBuffers: Buffer[] = [];
33
- const directory = path.join(...['.', 'modules'].concat(withinModule ?? []));
34
-
35
- const child = spawn('find', [directory]);
36
- child.stdout.on('data', (chunk: Buffer) => {
37
- buffers.push(chunk);
38
- });
39
-
40
- child.stderr.on('data', (chunk: Buffer) => {
41
- errorBuffers.push(chunk);
42
- });
43
-
44
- child.on('close', code => {
45
- if (!!code && code > 0) {
46
- reject(new Error('exited with error code: ' + code.toString()));
47
- }
48
-
49
- const output = Buffer.concat(buffers).toString('utf8');
50
-
51
- const files = output.trim().split('\n');
52
-
53
- const found = files.find(file => file.endsWith(`/${fileName}`));
54
-
55
- if (!found) {
56
- reject(new Error('File not found: ' + fileName));
57
- return;
58
- }
59
-
60
- resolve(path.join(rootPath, found));
61
- });
62
- });
63
- };
64
- return {
65
- name,
66
- rootPath,
67
- findFile,
68
- updateFile: async (file, withinModule, updater) => {
69
- const path = await findFile(file, withinModule);
70
- const contents = await readFile(path);
71
- const updated = await updater(contents);
72
- await writeFile(path, updated);
73
- },
74
- createFile: async (filePath, withinModule, source) => {
75
- const fullPath = path.resolve(path.join(rootPath, withinModule ? `modules/${withinModule}` : '.', filePath));
76
- await mkdir(path.dirname(fullPath), { recursive: true });
77
- await writeFile(fullPath, source);
78
- return fullPath;
79
- },
80
- };
81
- }
82
-
83
- type LineMatcher = (line: string) => boolean;
84
-
85
- export function lineMatches(search: string | RegExp): LineMatcher {
86
- return line => {
87
- if (typeof search === 'string') {
88
- return line.toString().includes(search);
89
- }
90
- return search.test(line);
91
- };
92
- }
93
-
94
- export const atBeginning: LineMatcher = () => true;
95
-
96
- export function insertLine(position: 'before' | 'after', search: LineMatcher, content: string | Buffer): FileUpdater {
97
- const match = (content: Buffer | string): boolean => search(content.toString());
98
- return contents => {
99
- let found = false;
100
- let buffer = Buffer.from([]);
101
- for (const line of eachLine(contents)) {
102
- const bufferLine = typeof line === 'string' ? Buffer.from(line) : line;
103
- if (position === 'after') {
104
- buffer = Buffer.concat([buffer, bufferLine]);
105
- }
106
- if (!found && match(line)) {
107
- found = true;
108
- buffer = Buffer.concat([buffer, typeof content === 'string' ? Buffer.from(content) : content]);
109
- }
110
- if (position === 'before') {
111
- buffer = Buffer.concat([buffer, bufferLine]);
112
- }
113
- }
114
- return Promise.resolve(buffer);
115
- };
116
- }
117
-
118
- export function insertLineBefore(search: LineMatcher, content: string | Buffer): FileUpdater {
119
- return insertLine('before', search, content);
120
- }
121
-
122
- export function insertLineAfter(search: LineMatcher, content: string | Buffer): FileUpdater {
123
- return insertLine('after', search, content);
124
- }
125
-
126
- export async function findDefinitionForTokenInFile(
127
- context: TaskContext,
128
- token: string,
129
- file: string,
130
- valdiModuleName?: string,
131
- ): Promise<[pathDescriptor: string, position: FilePosition, location: { file: string }, token: string]> {
132
- const appSource = await context.project.findFile(file, valdiModuleName);
133
- const position = await lineAndOffset(token, appSource);
134
- const definition = await context.client.command('definition', {
135
- file: appSource,
136
- line: position.line,
137
- offset: position.offset + 1,
138
- });
139
-
140
- if ('success' in definition && !definition['success']) {
141
- console.error(definition['message']);
142
- throw new Error('failed to get typeDefinition');
143
- }
144
-
145
- const body = definition['body'] as { file: string; start: { line: number; offset: number } }[];
146
- const location = body.at(0);
147
-
148
- if (!location) {
149
- throw new Error('No library definitions found for: ' + token + ' at ' + JSON.stringify(position));
150
- }
151
-
152
- return [`${location.file}:${location.start.line}:${location.start.offset}`, position, location, token];
153
- }
@@ -1,37 +0,0 @@
1
- export function* eachLine(chunkOrString: Buffer | string): Generator<Buffer | string> {
2
- let position = 0;
3
- const chunk = typeof chunkOrString === 'string' ? Buffer.from(chunkOrString) : chunkOrString;
4
- while (position < chunk.length) {
5
- const newline = chunk.indexOf('\n', position);
6
- if (newline === -1) {
7
- yield chunk.subarray(position).toString('utf8') + '\n';
8
- break;
9
- }
10
- yield chunk.subarray(position, newline).toString('utf8') + `\n`;
11
- position = newline + 1;
12
- }
13
- }
14
-
15
- export async function* pipeEachLine(source: AsyncGenerator<Buffer | string>): AsyncGenerator<Buffer | string> {
16
- for await (const chunk of source) {
17
- for (const line of eachLine(chunk)) {
18
- yield line;
19
- }
20
- }
21
- }
22
-
23
- /**
24
- * Reads the input of source and calls `fn` for each line as a side-effect.
25
- *
26
- * The input/output is not changed and cannot be mutated by the callback.
27
- */
28
- export function onEachLine(
29
- fn: (line: Buffer) => void,
30
- ): (source: AsyncGenerator<Buffer | string>) => AsyncGenerator<string | Buffer> {
31
- return async function* (source) {
32
- for await (const line of pipeEachLine(source)) {
33
- fn(typeof line === 'string' ? Buffer.from(line) : line);
34
- yield line;
35
- }
36
- };
37
- }
@@ -1,217 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { readFile } from 'node:fs/promises';
3
- import { run } from './CommandHelpers';
4
-
5
- const HEADER_END = '\r\n\r\n';
6
-
7
- export interface TSServerClient {
8
- command: (command: string, args?: Record<string, unknown>) => Promise<Record<string, unknown>>;
9
- disconnect: () => Promise<number>;
10
- }
11
-
12
- export function createClient(workingDir: string): TSServerClient {
13
- const reserveSequence = createNonceService();
14
- const read = createMessageBuffer();
15
-
16
- // eslint-disable-next-line unicorn/prefer-event-target
17
- const queue = new EventEmitter<{
18
- response: [Record<string, unknown>];
19
- message: [Record<string, unknown>];
20
- }>();
21
-
22
- const service = run('npx', ['tsserver'], {cwd: workingDir});
23
-
24
- service.process.stdout?.on('data', (chunk: Buffer) => {
25
- for (const [message] of read(chunk)) {
26
- if ('type' in message && message['type'] === 'response') {
27
- queue.emit('response', message);
28
- }
29
- queue.emit('message', message);
30
- }
31
- });
32
-
33
- service.process.stderr?.pipe(process.stderr)
34
-
35
- const send = (
36
- request: Record<string, unknown>,
37
- { timeout = 300000 }: { timeout?: number } = {},
38
- ): Promise<Record<string, unknown>> => {
39
- const seq = reserveSequence();
40
- const body = JSON.stringify({
41
- seq,
42
- ...request,
43
- });
44
- const payload = body + '\r\n';
45
- service.process.stdin.write(payload);
46
-
47
- return withTimeout(
48
- new Promise(resolve => {
49
- const listener = (message: Record<string, unknown>) => {
50
- if ('request_seq' in message && message['request_seq'] !== seq) {
51
- return;
52
- }
53
- queue.removeListener('response', listener);
54
- resolve(message);
55
- };
56
- queue.addListener('response', listener);
57
- }),
58
- timeout,
59
- );
60
- };
61
-
62
- return {
63
- command: (command: string, args?: Record<string, unknown>) =>
64
- send({
65
- command,
66
- ...(args ? { arguments: args } : null),
67
- }),
68
- disconnect: () => {
69
- service.process.stdin.end();
70
- service.process.kill('SIGINT');
71
- return service.wait();
72
- },
73
- };
74
- }
75
-
76
- export interface FilePosition {
77
- /**
78
- * 1 indexed line number (first line is line 1)
79
- */
80
- line: number;
81
- /**
82
- * 1 indexed column number (first column is column 1)
83
- */
84
- offset: number;
85
- /**
86
- * 0-index within the file content, the nth character
87
- */
88
- position: number;
89
- }
90
-
91
- export async function lineAndOffset(searchToken: string, file: string): Promise<FilePosition> {
92
- const buffer = await readFile(file);
93
- const position = buffer.indexOf(searchToken);
94
-
95
- if (position === -1) {
96
- throw new Error('searchToken not found in file');
97
- }
98
-
99
- let line = 1;
100
- let index = 0;
101
- let offset = -1;
102
- while (index <= position) {
103
- const nextLine = buffer.indexOf('\n', index);
104
- if (nextLine < position) {
105
- line += 1;
106
- index = nextLine + 1;
107
- continue;
108
- } else {
109
- offset = position - index;
110
- break;
111
- }
112
- }
113
- return { line, offset: Math.max(0, offset), position };
114
- }
115
-
116
- function withTimeout<T>(promise: Promise<T>, ms: number | false = 300000): Promise<T> {
117
- if (ms === false) {
118
- return promise;
119
- }
120
- let timer: NodeJS.Timeout;
121
- return Promise.race([
122
- new Promise<never>((_resolve, reject) => {
123
- timer = setTimeout(() => reject(new Error('timeout')), ms);
124
- }),
125
- promise.then(value => {
126
- clearTimeout(timer);
127
- return value;
128
- }),
129
- ]);
130
- }
131
-
132
- function* eachLine(buffer: Buffer) {
133
- let index = 0;
134
- while (index > -1 && index < buffer.length) {
135
- const endIndex = buffer.indexOf('\n', index);
136
- if (endIndex === -1) {
137
- yield buffer.subarray(index);
138
- break;
139
- }
140
- yield buffer.subarray(index, endIndex);
141
- index = endIndex;
142
- }
143
- }
144
-
145
- function* parseHeaders(chunk: Buffer): Generator<[name: string, value: string]> {
146
- for (const line of eachLine(chunk)) {
147
- const sep = line.indexOf(':');
148
- const name = line.subarray(0, sep);
149
- const value = line.subarray(sep + 1);
150
- yield [name.toString('utf8'), value.toString('utf8').trim()];
151
- }
152
- }
153
-
154
- /**
155
- * Create a statefull message buffer that parses TSServer messages.
156
- *
157
- * @returns {(chunk: Buffer) => Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]>}
158
- */
159
- function createMessageBuffer(): (
160
- chunk: Buffer,
161
- ) => Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]> {
162
- let buffer = Buffer.from([]);
163
- /**
164
- *
165
- * @param {Buffer} chunk
166
- * @return {Generator<[body: Record<string, unknown>, headers: Array<[name: string, value: string]>]>}
167
- */
168
- return function* read(chunk) {
169
- buffer = Buffer.concat([buffer, chunk]);
170
-
171
- let position = 0;
172
-
173
- while (position < buffer.length) {
174
- const headerSuffix = buffer.indexOf(HEADER_END, position);
175
-
176
- if (headerSuffix === -1) {
177
- throw new Error('no headers ' + buffer.toString('utf8'));
178
- }
179
-
180
- const headers: [string, string][] = Array.from(parseHeaders(buffer.subarray(position, headerSuffix)));
181
-
182
- // Content length
183
- const contentLength = Number.parseInt(
184
- headers.find(([name]) => name === 'Content-Length')?.[1] ?? Number.NaN.toString(),
185
- );
186
- if (Number.isNaN(contentLength)) {
187
- throw new TypeError('invalid message, no Content-Length');
188
- }
189
-
190
- const bodyStart = headerSuffix + HEADER_END.length;
191
- const bodyEnd = bodyStart + contentLength;
192
-
193
- if (bodyEnd > buffer.length) {
194
- buffer = buffer.subarray(position);
195
- return;
196
- }
197
-
198
- yield [JSON.parse(buffer.subarray(bodyStart, bodyEnd).toString('utf8')), headers];
199
-
200
- position = bodyEnd;
201
- }
202
- };
203
- }
204
-
205
- /**
206
- * Every time the returned function is called it will return a new sequenc.
207
- *
208
- * @returns {() => number}
209
- */
210
- function createNonceService() {
211
- let sequence = 1;
212
- return () => {
213
- const seq = sequence;
214
- sequence += 1;
215
- return seq;
216
- };
217
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "rootDirs": [],
5
- "rootDir": "./src",
6
- },
7
- "include": ["./src/**/*.ts"]
8
- }
package/tsconfig.json DELETED
@@ -1,42 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Main settings
4
- "rootDirs": ["./src", "./test"],
5
- "outDir": "./dist",
6
-
7
- // Modules
8
- "module": "CommonJS",
9
- "moduleResolution": "node",
10
- "esModuleInterop": true,
11
- "resolveJsonModule": true,
12
-
13
- // Type Checking
14
- "exactOptionalPropertyTypes": true,
15
- "noFallthroughCasesInSwitch": true,
16
- "noImplicitOverride": true,
17
- "noImplicitReturns": true,
18
- "noPropertyAccessFromIndexSignature": true,
19
- "noUncheckedIndexedAccess": true,
20
- "noUnusedLocals": false,
21
- "noUnusedParameters": true,
22
- "strict": true,
23
-
24
- // Emit
25
- "importHelpers": true,
26
- "noEmitHelpers": true,
27
- "noEmitOnError": true,
28
- "removeComments": true,
29
-
30
- // Interop Constraints
31
- "allowSyntheticDefaultImports": true,
32
- "forceConsistentCasingInFileNames": true,
33
- "isolatedModules": true,
34
-
35
- // Language and Environment
36
- "experimentalDecorators": true,
37
- "lib": ["ESNext"],
38
- "target": "ESNext",
39
- "useDefineForClassFields": true
40
- },
41
- "include": ["./src/**/*.ts", "./test/**/*.ts"]
42
- }