@bockit/sequel 0.0.0-stage → 0.1.0

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 (104) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +191 -2
  3. package/THIRD_PARTY_NOTICES.md +268 -0
  4. package/binaries.json +106 -0
  5. package/dist/binaries/cache.d.ts +6 -0
  6. package/dist/binaries/cache.js +36 -0
  7. package/dist/binaries/ensure-binary.d.ts +10 -0
  8. package/dist/binaries/ensure-binary.js +85 -0
  9. package/dist/binaries/manifest.d.ts +30 -0
  10. package/dist/binaries/manifest.js +112 -0
  11. package/dist/binaries/platform.d.ts +3 -0
  12. package/dist/binaries/platform.js +10 -0
  13. package/dist/binaries/unpack.d.ts +2 -0
  14. package/dist/binaries/unpack.js +35 -0
  15. package/dist/binaries/verify.d.ts +2 -0
  16. package/dist/binaries/verify.js +16 -0
  17. package/dist/check.d.ts +9 -0
  18. package/dist/check.js +166 -0
  19. package/dist/cli.d.ts +2 -0
  20. package/dist/cli.js +324 -0
  21. package/dist/config/define-config.d.ts +23 -0
  22. package/dist/config/define-config.js +4 -0
  23. package/dist/config/load-config.d.ts +6 -0
  24. package/dist/config/load-config.js +34 -0
  25. package/dist/config/resolve-config.d.ts +34 -0
  26. package/dist/config/resolve-config.js +144 -0
  27. package/dist/db/connection.d.ts +6 -0
  28. package/dist/db/connection.js +38 -0
  29. package/dist/db/shadow.d.ts +11 -0
  30. package/dist/db/shadow.js +68 -0
  31. package/dist/engine/client.d.ts +24 -0
  32. package/dist/engine/client.js +123 -0
  33. package/dist/engine/diff.d.ts +12 -0
  34. package/dist/engine/diff.js +51 -0
  35. package/dist/errors.d.ts +3 -0
  36. package/dist/errors.js +5 -0
  37. package/dist/extras/snapshot.d.ts +3 -0
  38. package/dist/extras/snapshot.js +99 -0
  39. package/dist/files.d.ts +1 -0
  40. package/dist/files.js +15 -0
  41. package/dist/generate/generate-modules.d.ts +17 -0
  42. package/dist/generate/generate-modules.js +97 -0
  43. package/dist/generate/modules.d.ts +16 -0
  44. package/dist/generate/modules.js +118 -0
  45. package/dist/generate/pg-dump.d.ts +8 -0
  46. package/dist/generate/pg-dump.js +66 -0
  47. package/dist/generate/plugin-wrapper.d.ts +3 -0
  48. package/dist/generate/plugin-wrapper.js +20 -0
  49. package/dist/generate/sqlc.d.ts +27 -0
  50. package/dist/generate/sqlc.js +113 -0
  51. package/dist/generate/watch.d.ts +16 -0
  52. package/dist/generate/watch.js +73 -0
  53. package/dist/generator/generate.d.ts +21 -0
  54. package/dist/generator/generate.js +440 -0
  55. package/dist/generator/keys.d.ts +4 -0
  56. package/dist/generator/keys.js +24 -0
  57. package/dist/generator/lexer.d.ts +12 -0
  58. package/dist/generator/lexer.js +210 -0
  59. package/dist/generator/main.d.ts +1 -0
  60. package/dist/generator/main.js +12 -0
  61. package/dist/generator/pg-array-helper.d.ts +2 -0
  62. package/dist/generator/pg-array-helper.js +53 -0
  63. package/dist/generator/plugin.d.ts +6 -0
  64. package/dist/generator/plugin.js +26 -0
  65. package/dist/generator/request.d.ts +57 -0
  66. package/dist/generator/request.js +96 -0
  67. package/dist/generator/select-list.d.ts +27 -0
  68. package/dist/generator/select-list.js +580 -0
  69. package/dist/generator/strings.d.ts +2 -0
  70. package/dist/generator/strings.js +34 -0
  71. package/dist/generator/types.d.ts +23 -0
  72. package/dist/generator/types.js +216 -0
  73. package/dist/index.d.ts +2 -0
  74. package/dist/index.js +2 -0
  75. package/dist/migrate/adopt-prisma.d.ts +23 -0
  76. package/dist/migrate/adopt-prisma.js +119 -0
  77. package/dist/migrate/deploy.d.ts +7 -0
  78. package/dist/migrate/deploy.js +23 -0
  79. package/dist/migrate/drift.d.ts +10 -0
  80. package/dist/migrate/drift.js +36 -0
  81. package/dist/migrate/files.d.ts +19 -0
  82. package/dist/migrate/files.js +97 -0
  83. package/dist/migrate/history.d.ts +20 -0
  84. package/dist/migrate/history.js +54 -0
  85. package/dist/migrate/lint.d.ts +21 -0
  86. package/dist/migrate/lint.js +153 -0
  87. package/dist/migrate/new.d.ts +13 -0
  88. package/dist/migrate/new.js +41 -0
  89. package/dist/migrate/runner.d.ts +28 -0
  90. package/dist/migrate/runner.js +124 -0
  91. package/dist/migrate/sql-text.d.ts +33 -0
  92. package/dist/migrate/sql-text.js +233 -0
  93. package/dist/schema/schema.d.ts +16 -0
  94. package/dist/schema/schema.js +111 -0
  95. package/dist/schema/unsupported.d.ts +3 -0
  96. package/dist/schema/unsupported.js +36 -0
  97. package/dist/schema/wasm.d.ts +8 -0
  98. package/dist/schema/wasm.js +32 -0
  99. package/package.json +50 -4
  100. package/vendor/prisma-schema-wasm/LICENSE +201 -0
  101. package/vendor/prisma-schema-wasm/README.md +32 -0
  102. package/vendor/prisma-schema-wasm/package.json +3 -0
  103. package/vendor/prisma-schema-wasm/prisma_schema_build.js +539 -0
  104. package/vendor/prisma-schema-wasm/prisma_schema_build_bg.wasm +0 -0
@@ -0,0 +1,12 @@
1
+ // sqlc runs this as its process plugin, through the per-run wrapper `src/generate/` writes
2
+ // (R1). It reads nothing but stdin, and ignores its one argument.
3
+ import { runPlugin } from './plugin.js';
4
+ const chunks = [];
5
+ for await (const chunk of process.stdin)
6
+ chunks.push(chunk);
7
+ const { stdout, stderr, exitCode } = runPlugin(Buffer.concat(chunks).toString('utf8'));
8
+ if (stdout !== '')
9
+ process.stdout.write(stdout);
10
+ if (stderr !== '')
11
+ process.stderr.write(stderr);
12
+ process.exitCode = exitCode;
@@ -0,0 +1,2 @@
1
+ export declare const HELPER_NAME = "parsePgArray";
2
+ export declare const PG_ARRAY_HELPER = "function parsePgArray(value: unknown): any {\n if (typeof value !== 'string') {\n return value\n }\n const text = value\n let pos = text.indexOf('{')\n if (pos === -1) {\n return []\n }\n const parse = (): unknown[] => {\n const items: unknown[] = []\n pos++\n while (pos < text.length) {\n const char = text.charAt(pos)\n if (char === '}') {\n pos++\n return items\n }\n if (char === ',') {\n pos++\n } else if (char === '{') {\n items.push(parse())\n } else if (char === '\"') {\n let item = ''\n pos++\n while (pos < text.length && text.charAt(pos) !== '\"') {\n if (text.charAt(pos) === '\\\\') {\n pos++\n }\n item += text.charAt(pos)\n pos++\n }\n pos++\n items.push(item)\n } else {\n const start = pos\n while (pos < text.length && text.charAt(pos) !== ',' && text.charAt(pos) !== '}') {\n pos++\n }\n const item = text.slice(start, pos)\n items.push(item === 'NULL' ? null : item)\n }\n }\n return items\n }\n return parse()\n}\n";
@@ -0,0 +1,53 @@
1
+ // The name reserved for the helper, whether or not a module uses it (R17).
2
+ export const HELPER_NAME = 'parsePgArray';
3
+ // §13: parses Postgres's array output format, for the array types pg-types returns as text.
4
+ // The text is fixed: every module that needs it emits these same bytes (R50). It compiles
5
+ // under the settings of R15, and every loop advances or returns, so it terminates on any input.
6
+ export const PG_ARRAY_HELPER = `function parsePgArray(value: unknown): any {
7
+ if (typeof value !== 'string') {
8
+ return value
9
+ }
10
+ const text = value
11
+ let pos = text.indexOf('{')
12
+ if (pos === -1) {
13
+ return []
14
+ }
15
+ const parse = (): unknown[] => {
16
+ const items: unknown[] = []
17
+ pos++
18
+ while (pos < text.length) {
19
+ const char = text.charAt(pos)
20
+ if (char === '}') {
21
+ pos++
22
+ return items
23
+ }
24
+ if (char === ',') {
25
+ pos++
26
+ } else if (char === '{') {
27
+ items.push(parse())
28
+ } else if (char === '"') {
29
+ let item = ''
30
+ pos++
31
+ while (pos < text.length && text.charAt(pos) !== '"') {
32
+ if (text.charAt(pos) === '\\\\') {
33
+ pos++
34
+ }
35
+ item += text.charAt(pos)
36
+ pos++
37
+ }
38
+ pos++
39
+ items.push(item)
40
+ } else {
41
+ const start = pos
42
+ while (pos < text.length && text.charAt(pos) !== ',' && text.charAt(pos) !== '}') {
43
+ pos++
44
+ }
45
+ const item = text.slice(start, pos)
46
+ items.push(item === 'NULL' ? null : item)
47
+ }
48
+ }
49
+ return items
50
+ }
51
+ return parse()
52
+ }
53
+ `;
@@ -0,0 +1,6 @@
1
+ export type PluginOutput = {
2
+ stdout: string;
3
+ stderr: string;
4
+ exitCode: number;
5
+ };
6
+ export declare function runPlugin(input: string): PluginOutput;
@@ -0,0 +1,26 @@
1
+ import { generate } from './generate.js';
2
+ import { readRequest } from './request.js';
3
+ // R2–R6: a JSON GenerateRequest in, a JSON GenerateResponse out. On failure, nothing on
4
+ // stdout, every failure on stderr one per line, and exit 1.
5
+ export function runPlugin(input) {
6
+ let result;
7
+ try {
8
+ result = generate(readRequest(JSON.parse(input)));
9
+ }
10
+ catch (error) {
11
+ const message = error instanceof Error ? error.message : String(error);
12
+ return {
13
+ stdout: '',
14
+ stderr: `sequel's generator could not read sqlc's request: ${message}\n`,
15
+ exitCode: 1,
16
+ };
17
+ }
18
+ if (!result.ok) {
19
+ return { stdout: '', stderr: result.failures.map((line) => `${line}\n`).join(''), exitCode: 1 };
20
+ }
21
+ const files = result.files.map((file) => ({
22
+ name: file.name,
23
+ contents: Buffer.from(file.contents, 'utf8').toString('base64'),
24
+ }));
25
+ return { stdout: JSON.stringify({ files }), stderr: '', exitCode: 0 };
26
+ }
@@ -0,0 +1,57 @@
1
+ export type Identifier = {
2
+ catalog: string;
3
+ schema: string;
4
+ name: string;
5
+ };
6
+ export type Column = {
7
+ name: string;
8
+ not_null: boolean;
9
+ is_array: boolean;
10
+ is_func_call: boolean;
11
+ is_sqlc_slice: boolean;
12
+ type: Identifier | null;
13
+ embed_table: Identifier | null;
14
+ array_dims: number;
15
+ };
16
+ export type Parameter = {
17
+ number: number;
18
+ column: Column | null;
19
+ };
20
+ export type Query = {
21
+ text: string;
22
+ name: string;
23
+ cmd: string;
24
+ columns: Column[];
25
+ params: Parameter[];
26
+ comments: string[];
27
+ filename: string;
28
+ };
29
+ export type Table = {
30
+ rel: Identifier | null;
31
+ columns: {
32
+ name: string;
33
+ not_null: boolean;
34
+ }[];
35
+ };
36
+ export type Schema = {
37
+ name: string;
38
+ tables: Table[];
39
+ enums: {
40
+ name: string;
41
+ vals: string[];
42
+ }[];
43
+ };
44
+ export type Catalog = {
45
+ default_schema: string;
46
+ schemas: Schema[];
47
+ };
48
+ export type GenerateRequest = {
49
+ catalog: Catalog | null;
50
+ queries: Query[];
51
+ plugin_options: string;
52
+ };
53
+ export type BigintMode = 'string' | 'number' | 'bigint';
54
+ export type Options = {
55
+ bigint: BigintMode;
56
+ };
57
+ export declare function readRequest(value: unknown): GenerateRequest;
@@ -0,0 +1,96 @@
1
+ // The parts of sqlc's `GenerateRequest` the generator reads (R2). sqlc encodes it with
2
+ // protobuf's JSON mapping, using the proto field names, so a query's parameters are under
3
+ // `params`. Every field is present, absent messages are `null`, and `bytes` are base64.
4
+ // Reads the request leniently: a missing field takes its protobuf default, so hand-built
5
+ // requests in tests can leave out what they don't need.
6
+ export function readRequest(value) {
7
+ const request = record(value);
8
+ const catalog = request.catalog === null || request.catalog === undefined ? null : record(request.catalog);
9
+ return {
10
+ catalog: catalog === null
11
+ ? null
12
+ : {
13
+ default_schema: string(catalog.default_schema),
14
+ schemas: list(catalog.schemas).map((value) => {
15
+ const schema = record(value);
16
+ return {
17
+ name: string(schema.name),
18
+ tables: list(schema.tables).map((value) => {
19
+ const table = record(value);
20
+ return {
21
+ rel: identifier(table.rel),
22
+ columns: list(table.columns).map((value) => {
23
+ const column = record(value);
24
+ return { name: string(column.name), not_null: column.not_null === true };
25
+ }),
26
+ };
27
+ }),
28
+ enums: list(schema.enums).map((value) => {
29
+ const item = record(value);
30
+ return { name: string(item.name), vals: list(item.vals).map(string) };
31
+ }),
32
+ };
33
+ }),
34
+ },
35
+ queries: list(request.queries).map((value) => {
36
+ const query = record(value);
37
+ return {
38
+ text: string(query.text),
39
+ name: string(query.name),
40
+ cmd: string(query.cmd),
41
+ columns: list(query.columns).map(column),
42
+ params: list(query.params).map((value) => {
43
+ const parameter = record(value);
44
+ return {
45
+ number: typeof parameter.number === 'number' ? parameter.number : 0,
46
+ column: parameter.column === null || parameter.column === undefined
47
+ ? null
48
+ : column(parameter.column),
49
+ };
50
+ }),
51
+ comments: list(query.comments).map(string),
52
+ filename: string(query.filename),
53
+ };
54
+ }),
55
+ plugin_options: string(request.plugin_options),
56
+ };
57
+ }
58
+ function column(value) {
59
+ const item = record(value);
60
+ return {
61
+ name: string(item.name),
62
+ not_null: item.not_null === true,
63
+ is_array: item.is_array === true,
64
+ is_func_call: item.is_func_call === true,
65
+ is_sqlc_slice: item.is_sqlc_slice === true,
66
+ type: identifier(item.type),
67
+ embed_table: identifier(item.embed_table),
68
+ array_dims: typeof item.array_dims === 'number' ? item.array_dims : 0,
69
+ };
70
+ }
71
+ function identifier(value) {
72
+ if (value === null || value === undefined)
73
+ return null;
74
+ const item = record(value);
75
+ return { catalog: string(item.catalog), schema: string(item.schema), name: string(item.name) };
76
+ }
77
+ function record(value) {
78
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
79
+ throw new Error('the GenerateRequest is malformed: expected an object');
80
+ }
81
+ return value;
82
+ }
83
+ function list(value) {
84
+ if (value === null || value === undefined)
85
+ return [];
86
+ if (!Array.isArray(value))
87
+ throw new Error('the GenerateRequest is malformed: expected an array');
88
+ return value;
89
+ }
90
+ function string(value) {
91
+ if (value === null || value === undefined)
92
+ return '';
93
+ if (typeof value !== 'string')
94
+ throw new Error('the GenerateRequest is malformed: expected a string');
95
+ return value;
96
+ }
@@ -0,0 +1,27 @@
1
+ import { type Token } from './lexer.ts';
2
+ export type FromItem = {
3
+ table: {
4
+ schema: string | null;
5
+ name: string;
6
+ } | null;
7
+ alias: string | null;
8
+ nullable: boolean;
9
+ };
10
+ export type SelectList = {
11
+ items: Token[][] | null;
12
+ from: FromItem[] | null;
13
+ };
14
+ export declare function selectList(text: string, columnCount: number): SelectList;
15
+ export type Expression = {
16
+ tokens: Token[];
17
+ depth: number;
18
+ };
19
+ export declare function bare(item: Token[]): Expression;
20
+ export declare function isNeverNullCall(item: Token[]): boolean;
21
+ export declare function coalesce(item: Token[]): 'never-null' | 'nullable' | null;
22
+ export declare function isNullTest(item: Token[]): boolean;
23
+ export type ColumnLookup = (table: {
24
+ schema: string | null;
25
+ name: string;
26
+ }, column: string) => 'not-null' | 'nullable' | 'missing' | null;
27
+ export declare function arrayAggElementsNotNull(item: Token[], from: FromItem[] | null, lookup: ColumnLookup): boolean;