prostgles-server 4.2.619 → 4.2.620
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.
- package/debug/access-profile-source.patch +14 -0
- package/debug/client-profile-perf.cjs +17 -0
- package/debug/client-schema-test.log +10 -0
- package/debug/client-schema-types/DBGeneratedSchema.ts +57 -0
- package/debug/client-typecheck.ts +11 -0
- package/debug/profile-perf.cjs +26 -0
- package/debug/prostgles-types-4.0.282.tgz +0 -0
- package/debug/publish-schema-test.log +16 -0
- package/debug/run-client-schema.cjs +3 -0
- package/debug/run-publish-schema.cjs +3 -0
- package/debug/server-lib-tests.log +28 -0
- package/debug/types-pack.log +162 -0
- package/dist/DBSchemaBuilder/constants.d.ts +2 -0
- package/dist/DBSchemaBuilder/constants.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/constants.js +5 -0
- package/dist/DBSchemaBuilder/constants.js.map +1 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts +9 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js +77 -0
- package/dist/DBSchemaBuilder/getClientDBGeneratedSchemas.js.map +1 -0
- package/dist/DBSchemaBuilder/getColumnTypescriptDefinition.js +2 -2
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts +3 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.d.ts.map +1 -1
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js +7 -5
- package/dist/DBSchemaBuilder/getDBGeneratedSchema.js.map +1 -1
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts +4 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.d.ts.map +1 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.js +34 -0
- package/dist/DBSchemaBuilder/getPublishSchemas.js.map +1 -0
- package/dist/DboBuilder/DboBuilder.d.ts +5 -8
- package/dist/DboBuilder/DboBuilder.d.ts.map +1 -1
- package/dist/DboBuilder/DboBuilder.js +11 -14
- package/dist/DboBuilder/DboBuilder.js.map +1 -1
- package/dist/Prostgles.d.ts +3 -2
- package/dist/Prostgles.d.ts.map +1 -1
- package/dist/Prostgles.js +9 -3
- package/dist/Prostgles.js.map +1 -1
- package/dist/PublishParser/PublishParser.d.ts +3 -2
- package/dist/PublishParser/PublishParser.d.ts.map +1 -1
- package/dist/PublishParser/PublishParser.js +16 -5
- package/dist/PublishParser/PublishParser.js.map +1 -1
- package/dist/PublishParser/getFileTableRules.d.ts +2 -2
- package/dist/PublishParser/getFileTableRules.d.ts.map +1 -1
- package/dist/PublishParser/getFileTableRules.js +2 -2
- package/dist/PublishParser/getFileTableRules.js.map +1 -1
- package/dist/PublishParser/getPublishedTableNames.d.ts +4 -0
- package/dist/PublishParser/getPublishedTableNames.d.ts.map +1 -0
- package/dist/PublishParser/getPublishedTableNames.js +23 -0
- package/dist/PublishParser/getPublishedTableNames.js.map +1 -0
- package/dist/PublishParser/getSchemaFromPublish.d.ts.map +1 -1
- package/dist/PublishParser/getSchemaFromPublish.js +2 -13
- package/dist/PublishParser/getSchemaFromPublish.js.map +1 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts +7 -1
- package/dist/PublishParser/publishTypesAndUtils.d.ts.map +1 -1
- package/dist/PublishParser/validatePublishProfiles.d.ts +7 -0
- package/dist/PublishParser/validatePublishProfiles.d.ts.map +1 -0
- package/dist/PublishParser/validatePublishProfiles.js +27 -0
- package/dist/PublishParser/validatePublishProfiles.js.map +1 -0
- package/dist/SchemaWatch/SchemaWatch.js +1 -1
- package/dist/SchemaWatch/SchemaWatch.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/initProstgles.d.ts +2 -2
- package/dist/initProstgles.d.ts.map +1 -1
- package/dist/initProstgles.js +2 -4
- package/dist/initProstgles.js.map +1 -1
- package/dist/updateConfiguration.d.ts.map +1 -1
- package/dist/updateConfiguration.js +6 -2
- package/dist/updateConfiguration.js.map +1 -1
- package/eslint.config.mjs +1 -1
- package/lib/DBSchemaBuilder/constants.ts +1 -0
- package/lib/DBSchemaBuilder/getClientDBGeneratedSchemas.ts +91 -0
- package/lib/DBSchemaBuilder/getColumnTypescriptDefinition.ts +2 -2
- package/lib/DBSchemaBuilder/getDBGeneratedSchema.ts +11 -4
- package/lib/DBSchemaBuilder/getPublishSchemas.ts +41 -0
- package/lib/DboBuilder/DboBuilder.ts +15 -22
- package/lib/Prostgles.ts +10 -4
- package/lib/PublishParser/PublishParser.ts +24 -4
- package/lib/PublishParser/getFileTableRules.ts +3 -2
- package/lib/PublishParser/getPublishedTableNames.ts +29 -0
- package/lib/PublishParser/getSchemaFromPublish.ts +2 -17
- package/lib/PublishParser/publishTypesAndUtils.ts +7 -0
- package/lib/PublishParser/validatePublishProfiles.ts +22 -0
- package/lib/SchemaWatch/SchemaWatch.ts +1 -1
- package/lib/index.ts +1 -1
- package/lib/initProstgles.ts +7 -19
- package/lib/updateConfiguration.ts +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
--- /home/s/prostgles-types/scripts/check-type-instantiations.mjs
|
|
2
|
+
+++ /home/s/prostgles-types/scripts/check-type-instantiations.mjs
|
|
3
|
+
@@ -2,9 +2,9 @@
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
// Previous baseline: 107,408.
|
|
7
|
+
-// Baseline: 108,857, including insertColumns lookup for access profiles (+1.35%).
|
|
8
|
+
+// Baseline: 109,605, including insertColumns and cached schema references (+2.05%).
|
|
9
|
+
// The small margin avoids hiding meaningful inference regressions.
|
|
10
|
+
-const MAX_INSTANTIATIONS = 108_950;
|
|
11
|
+
+const MAX_INSTANTIATIONS = 109_700;
|
|
12
|
+
const tscPath = fileURLToPath(new URL("../node_modules/typescript/bin/tsc", import.meta.url));
|
|
13
|
+
const result = spawnSync(
|
|
14
|
+
process.execPath,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const ts = require('typescript');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const filename = path.resolve('debug/perf-schema.ts');
|
|
5
|
+
const clientFile = '/home/s/prostgles-client-js/lib/prostgles.ts';
|
|
6
|
+
const source = fs.readFileSync(clientFile, 'utf8');
|
|
7
|
+
const refs = fs.readFileSync('/home/s/prostgles-types/lib/insertTypes.ts', 'utf8');
|
|
8
|
+
const options = {strict:true,noImplicitAny:false,noEmit:true,skipLibCheck:true,target:ts.ScriptTarget.ES2022,module:ts.ModuleKind.CommonJS,esModuleInterop:true};
|
|
9
|
+
for (const variant of ['before','current','conditional','profiles']) {
|
|
10
|
+
const fixture = 'import type {DBHandlerClient} from "/home/s/prostgles-client-js/lib/prostgles";\ntype S = {' + Array.from({length:100},(_,i)=> `t${i}: {columns:{body:string; created_by:string}; ${variant === 'profiles' ? 'insertColumns:{body:string;created_by?:never};' : ''}}`).join(';') + '};\ndeclare const db: DBHandlerClient<S>;\n' + Array.from({length:100},(_,i)=> `db.t${i}.insert({body:""${variant === 'profiles' ? '' : ',created_by:""'}});`).join('\n');
|
|
11
|
+
const host = ts.createCompilerHost(options);
|
|
12
|
+
const readFile = host.readFile;
|
|
13
|
+
host.readFile = p => p === filename ? fixture : p === clientFile ? source.replace('"insertColumns" extends keyof Schema[tov_name] ? tov_name : never', variant === 'before' ? 'never' : variant === 'current' ? 'tov_name' : '"insertColumns" extends keyof Schema[tov_name] ? tov_name : never') : p.endsWith('/prostgles-types/dist/insertTypes.d.ts') ? refs : readFile(p);
|
|
14
|
+
const program = ts.createProgram([filename], options, host);
|
|
15
|
+
const errors = ts.getPreEmitDiagnostics(program);
|
|
16
|
+
console.log(variant, program.getInstantiationCount(), errors.length);
|
|
17
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* Schema definition generated by prostgles-server */
|
|
2
|
+
|
|
3
|
+
export type DBGeneratedSchema = {
|
|
4
|
+
"client_schema_types.correspondence": {
|
|
5
|
+
columns: {
|
|
6
|
+
body: string;
|
|
7
|
+
created_by: string;
|
|
8
|
+
id?: number;
|
|
9
|
+
internal?: string;
|
|
10
|
+
note?: null | string;
|
|
11
|
+
synced: number | string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
};
|
|
15
|
+
"client_schema_types.private_table": {
|
|
16
|
+
columns: {
|
|
17
|
+
id?: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Data types as expected when selecting from the database
|
|
26
|
+
* */
|
|
27
|
+
export type DBSchema = {
|
|
28
|
+
[K in keyof DBGeneratedSchema]: Required<DBGeneratedSchema[K]["columns"]>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Data types as expected when inserting into the database (optional fields might be nullable/with defaults)
|
|
33
|
+
* */
|
|
34
|
+
export type DBSchemaForInsert = {
|
|
35
|
+
[K in keyof DBGeneratedSchema]: DBGeneratedSchema[K]["columns"];
|
|
36
|
+
};
|
|
37
|
+
/** Insert access profiles. Row types retain the database schema; runtime permissions still apply. */
|
|
38
|
+
|
|
39
|
+
export type AdminDBSchema = {
|
|
40
|
+
"client_schema_types.correspondence": DBGeneratedSchema["client_schema_types.correspondence"] & { insertColumns: Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "body" | "created_by" | "id" | "internal" | "note"> & Partial<Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "synced">> };
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type GuestDBSchema = {
|
|
44
|
+
"client_schema_types.correspondence": DBGeneratedSchema["client_schema_types.correspondence"] & { insertColumns: Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "body" | "id" | "note"> & Partial<Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "synced">> & { "created_by"?: never; "internal"?: never } };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ViewerDBSchema = {
|
|
48
|
+
"client_schema_types.correspondence": DBGeneratedSchema["client_schema_types.correspondence"] & { insertColumns: never };
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** Permissive insert inputs across all supplied profiles; narrow to a named profile for exact inputs. */
|
|
52
|
+
|
|
53
|
+
export type ClientDBSchema = {
|
|
54
|
+
"client_schema_types.correspondence": DBGeneratedSchema["client_schema_types.correspondence"] & { insertColumns: Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "body" | "id" | "note"> & Partial<Pick<DBGeneratedSchema["client_schema_types.correspondence"]["columns"], "created_by" | "internal" | "synced">> };
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export type GeneratedFunctionSchema = Record<string, never>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DBHandlerClient } from '/home/s/prostgles-client-js/lib/prostgles';
|
|
2
|
+
type S = { correspondence: { columns: {body: string; created_by: string}; insertColumns: {body: string; created_by?: never} } };
|
|
3
|
+
declare const db: DBHandlerClient<S>;
|
|
4
|
+
async () => {
|
|
5
|
+
const row = await db.correspondence.insert({body:'hello'}, {returning:'*'});
|
|
6
|
+
row.created_by satisfies string;
|
|
7
|
+
// @ts-expect-error forced field must be excluded via the actual client handler
|
|
8
|
+
await db.correspondence.insert({body:'hello', created_by:'other'});
|
|
9
|
+
// @ts-expect-error required input remains required via the actual client handler
|
|
10
|
+
await db.correspondence.insert({});
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const ts = require('/home/s/prostgles-types/node_modules/typescript');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const root = '/home/s/prostgles-types';
|
|
4
|
+
const config = ts.readConfigFile(root + '/tsconfig.json', ts.sys.readFile);
|
|
5
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, root);
|
|
6
|
+
const sourcePath = root + '/lib/index.ts';
|
|
7
|
+
const source = fs.readFileSync(sourcePath, 'utf8');
|
|
8
|
+
const begin = source.indexOf('type GetInsertColumns<');
|
|
9
|
+
const end = source.indexOf('/**', begin);
|
|
10
|
+
const variants = {
|
|
11
|
+
current: source.slice(begin, end),
|
|
12
|
+
indexed: `type GetInsertColumns<TD extends AnyObject, S, TName extends PropertyKey> =
|
|
13
|
+
[TName] extends [never] ? TD
|
|
14
|
+
: TName extends keyof S ? S[TName] extends { insertColumns: infer C extends AnyObject } ? C : TD : TD;\n\n`,
|
|
15
|
+
keyed: `type GetInsertColumns<TD extends AnyObject, S, TName extends PropertyKey> =
|
|
16
|
+
[TName] extends [never] ? TD
|
|
17
|
+
: TName extends keyof S ? "insertColumns" extends keyof S[TName] ? S[TName]["insertColumns"] & AnyObject : TD : TD;\n\n`,
|
|
18
|
+
};
|
|
19
|
+
for (const [name, replacement] of Object.entries(variants)) {
|
|
20
|
+
const host = ts.createCompilerHost(parsed.options);
|
|
21
|
+
const readFile = host.readFile;
|
|
22
|
+
host.readFile = p => p === sourcePath ? source.slice(0, begin) + replacement + source.slice(end) : readFile(p);
|
|
23
|
+
const program = ts.createProgram(parsed.fileNames, {...parsed.options, noEmit: true}, host);
|
|
24
|
+
const errors = ts.getPreEmitDiagnostics(program);
|
|
25
|
+
console.log(name, program.getInstantiationCount(), errors.length);
|
|
26
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Prostgles: Created typescript schema definition file:
|
|
2
|
+
DBGeneratedSchema.ts
|
|
3
|
+
Prostgles: Created typescript schema definition file:
|
|
4
|
+
DBGeneratedSchema.ts
|
|
5
|
+
Prostgles: Created typescript schema definition file:
|
|
6
|
+
DBGeneratedSchema.ts
|
|
7
|
+
destroying prgl instance
|
|
8
|
+
✔ client insert profiles compile at startup and follow user types (1754.569494ms)
|
|
9
|
+
ℹ tests 1
|
|
10
|
+
ℹ suites 0
|
|
11
|
+
ℹ pass 1
|
|
12
|
+
ℹ fail 0
|
|
13
|
+
ℹ cancelled 0
|
|
14
|
+
ℹ skipped 0
|
|
15
|
+
ℹ todo 0
|
|
16
|
+
ℹ duration_ms 2214.359263
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
▶ DBSchemaBuilder type tests
|
|
2
|
+
✔ Type checks (0.426827ms)
|
|
3
|
+
✔ DBSchemaBuilder type tests (1.024575ms)
|
|
4
|
+
▶ getServerFunctionReturnTypes
|
|
5
|
+
✔ reads grouped functions and stops at recursive types (1201.035807ms)
|
|
6
|
+
✔ getServerFunctionReturnTypes (1201.930743ms)
|
|
7
|
+
▶ DboBuilder onCommit
|
|
8
|
+
✔ awaits callbacks after commit and logs callback errors (5.706408ms)
|
|
9
|
+
✔ discards callbacks on rollback (0.46639ms)
|
|
10
|
+
✔ DboBuilder onCommit (7.067115ms)
|
|
11
|
+
▶ dboBuilderUtils
|
|
12
|
+
✔ getErrorAsObject circular (0.758856ms)
|
|
13
|
+
✔ dboBuilderUtils (1.347576ms)
|
|
14
|
+
▶ defineFunction type test
|
|
15
|
+
✔ Type test (0.537399ms)
|
|
16
|
+
✔ defineFunction type test (1.119933ms)
|
|
17
|
+
✔ managed files preserve hooks on other tables and append file hooks (1.458829ms)
|
|
18
|
+
▶ DBOFullyTyped test
|
|
19
|
+
✔ Type test (0.897006ms)
|
|
20
|
+
✔ DBOFullyTyped test (2.122283ms)
|
|
21
|
+
ℹ tests 8
|
|
22
|
+
ℹ suites 6
|
|
23
|
+
ℹ pass 8
|
|
24
|
+
ℹ fail 0
|
|
25
|
+
ℹ cancelled 0
|
|
26
|
+
ℹ skipped 0
|
|
27
|
+
ℹ todo 0
|
|
28
|
+
ℹ duration_ms 1475.174798
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
|
|
2
|
+
> prostgles-types@4.0.282 prepack
|
|
3
|
+
> npm run build
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
> prostgles-types@4.0.282 prebuild
|
|
7
|
+
> tsc --noEmit -p tsconfig.browser.json
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
> prostgles-types@4.0.282 build
|
|
11
|
+
> rm -rf ./dist/* && tsc && webpack --config webpack.prod.js
|
|
12
|
+
|
|
13
|
+
asset index_umd.js 40.7 KiB [emitted] [minimized] (name: index_umd)
|
|
14
|
+
modules by path ./dist/*.js 49.8 KiB
|
|
15
|
+
./dist/index.js 8.35 KiB [built] [code generated]
|
|
16
|
+
./dist/util.js 9.99 KiB [built] [code generated]
|
|
17
|
+
./dist/auth.js 109 bytes [built] [code generated]
|
|
18
|
+
+ 6 modules
|
|
19
|
+
modules by path ./dist/JSONBSchemaValidation/*.js 31.2 KiB
|
|
20
|
+
./dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.js 5.01 KiB [built] [code generated]
|
|
21
|
+
./dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.js 5.73 KiB [built] [code generated]
|
|
22
|
+
./dist/JSONBSchemaValidation/JSONBSchemaValidation.js 18.4 KiB [built] [code generated]
|
|
23
|
+
+ 2 modules
|
|
24
|
+
modules by path ./dist/utilFuncs/*.js 5.19 KiB
|
|
25
|
+
./dist/utilFuncs/includes.js 219 bytes [built] [code generated]
|
|
26
|
+
./dist/utilFuncs/index.js 929 bytes [built] [code generated]
|
|
27
|
+
./dist/utilFuncs/isEqual.js 3 KiB [built] [code generated]
|
|
28
|
+
./dist/utilFuncs/tryCatchV2.js 1.07 KiB [built] [code generated]
|
|
29
|
+
webpack 5.109.2 compiled successfully in 457 ms
|
|
30
|
+
npm notice
|
|
31
|
+
npm notice 📦 prostgles-types@4.0.282
|
|
32
|
+
npm notice Tarball Contents
|
|
33
|
+
npm notice 1.1kB LICENSE
|
|
34
|
+
npm notice 97B README.md
|
|
35
|
+
npm notice 4.4kB dist/auth.d.ts
|
|
36
|
+
npm notice 3.1kB dist/auth.d.ts.map
|
|
37
|
+
npm notice 109B dist/auth.js
|
|
38
|
+
npm notice 100B dist/auth.js.map
|
|
39
|
+
npm notice 4.6kB dist/files.d.ts
|
|
40
|
+
npm notice 816B dist/files.d.ts.map
|
|
41
|
+
npm notice 2.9kB dist/files.js
|
|
42
|
+
npm notice 2.7kB dist/files.js.map
|
|
43
|
+
npm notice 9.9kB dist/filters.d.ts
|
|
44
|
+
npm notice 4.9kB dist/filters.d.ts.map
|
|
45
|
+
npm notice 4.8kB dist/filters.js
|
|
46
|
+
npm notice 2.5kB dist/filters.js.map
|
|
47
|
+
npm notice 41.6kB dist/index_umd.js
|
|
48
|
+
npm notice 40.8kB dist/index.d.ts
|
|
49
|
+
npm notice 28.2kB dist/index.d.ts.map
|
|
50
|
+
npm notice 8.6kB dist/index.js
|
|
51
|
+
npm notice 6.0kB dist/index.js.map
|
|
52
|
+
npm notice 1.2kB dist/insertTypes.d.ts
|
|
53
|
+
npm notice 1.4kB dist/insertTypes.d.ts.map
|
|
54
|
+
npm notice 116B dist/insertTypes.js
|
|
55
|
+
npm notice 114B dist/insertTypes.js.map
|
|
56
|
+
npm notice 457B dist/insertUpdateUtils.d.ts
|
|
57
|
+
npm notice 740B dist/insertUpdateUtils.d.ts.map
|
|
58
|
+
npm notice 502B dist/insertUpdateUtils.js
|
|
59
|
+
npm notice 613B dist/insertUpdateUtils.js.map
|
|
60
|
+
npm notice 358B dist/joinHelpers.d.ts
|
|
61
|
+
npm notice 333B dist/joinHelpers.d.ts.map
|
|
62
|
+
npm notice 799B dist/joinHelpers.js
|
|
63
|
+
npm notice 651B dist/joinHelpers.js.map
|
|
64
|
+
npm notice 413B dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.d.ts
|
|
65
|
+
npm notice 497B dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.d.ts.map
|
|
66
|
+
npm notice 5.1kB dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.js
|
|
67
|
+
npm notice 5.2kB dist/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.js.map
|
|
68
|
+
npm notice 476B dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.d.ts
|
|
69
|
+
npm notice 532B dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.d.ts.map
|
|
70
|
+
npm notice 5.9kB dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.js
|
|
71
|
+
npm notice 6.4kB dist/JSONBSchemaValidation/getJSONBSchemaTSTypes.js.map
|
|
72
|
+
npm notice 11.4kB dist/JSONBSchemaValidation/JSONBSchema.d.ts
|
|
73
|
+
npm notice 10.4kB dist/JSONBSchemaValidation/JSONBSchema.d.ts.map
|
|
74
|
+
npm notice 743B dist/JSONBSchemaValidation/JSONBSchema.js
|
|
75
|
+
npm notice 652B dist/JSONBSchemaValidation/JSONBSchema.js.map
|
|
76
|
+
npm notice 1.8kB dist/JSONBSchemaValidation/JSONBSchemaValidation.d.ts
|
|
77
|
+
npm notice 1.7kB dist/JSONBSchemaValidation/JSONBSchemaValidation.d.ts.map
|
|
78
|
+
npm notice 18.9kB dist/JSONBSchemaValidation/JSONBSchemaValidation.js
|
|
79
|
+
npm notice 18.3kB dist/JSONBSchemaValidation/JSONBSchemaValidation.js.map
|
|
80
|
+
npm notice 413B dist/JSONBSchemaValidation/utils.d.ts
|
|
81
|
+
npm notice 338B dist/JSONBSchemaValidation/utils.d.ts.map
|
|
82
|
+
npm notice 1.3kB dist/JSONBSchemaValidation/utils.js
|
|
83
|
+
npm notice 1.1kB dist/JSONBSchemaValidation/utils.js.map
|
|
84
|
+
npm notice 134B dist/md5.d.ts
|
|
85
|
+
npm notice 197B dist/md5.d.ts.map
|
|
86
|
+
npm notice 6.4kB dist/md5.js
|
|
87
|
+
npm notice 12.5kB dist/md5.js.map
|
|
88
|
+
npm notice 21.2kB dist/replication.d.ts
|
|
89
|
+
npm notice 4.4kB dist/replication.d.ts.map
|
|
90
|
+
npm notice 8.1kB dist/replication.js
|
|
91
|
+
npm notice 6.7kB dist/replication.js.map
|
|
92
|
+
npm notice 3.0kB dist/selectTypesV2.d.ts
|
|
93
|
+
npm notice 3.8kB dist/selectTypesV2.d.ts.map
|
|
94
|
+
npm notice 665B dist/selectTypesV2.js
|
|
95
|
+
npm notice 785B dist/selectTypesV2.js.map
|
|
96
|
+
npm notice 50B dist/typeTests.d.ts
|
|
97
|
+
npm notice 112B dist/typeTests.d.ts.map
|
|
98
|
+
npm notice 4.1kB dist/typeTests.js
|
|
99
|
+
npm notice 5.4kB dist/typeTests.js.map
|
|
100
|
+
npm notice 216B dist/typeUtils.d.ts
|
|
101
|
+
npm notice 363B dist/typeUtils.d.ts.map
|
|
102
|
+
npm notice 114B dist/typeUtils.js
|
|
103
|
+
npm notice 110B dist/typeUtils.js.map
|
|
104
|
+
npm notice 4.2kB dist/util.d.ts
|
|
105
|
+
npm notice 5.0kB dist/util.d.ts.map
|
|
106
|
+
npm notice 10.2kB dist/util.js
|
|
107
|
+
npm notice 11.3kB dist/util.js.map
|
|
108
|
+
npm notice 124B dist/utilFuncs/includes.d.ts
|
|
109
|
+
npm notice 240B dist/utilFuncs/includes.d.ts.map
|
|
110
|
+
npm notice 219B dist/utilFuncs/includes.js
|
|
111
|
+
npm notice 262B dist/utilFuncs/includes.js.map
|
|
112
|
+
npm notice 120B dist/utilFuncs/index.d.ts
|
|
113
|
+
npm notice 178B dist/utilFuncs/index.d.ts.map
|
|
114
|
+
npm notice 929B dist/utilFuncs/index.js
|
|
115
|
+
npm notice 168B dist/utilFuncs/index.js.map
|
|
116
|
+
npm notice 302B dist/utilFuncs/isEqual.d.ts
|
|
117
|
+
npm notice 274B dist/utilFuncs/isEqual.d.ts.map
|
|
118
|
+
npm notice 3.1kB dist/utilFuncs/isEqual.js
|
|
119
|
+
npm notice 3.6kB dist/utilFuncs/isEqual.js.map
|
|
120
|
+
npm notice 397B dist/utilFuncs/tryCatchV2.d.ts
|
|
121
|
+
npm notice 593B dist/utilFuncs/tryCatchV2.d.ts.map
|
|
122
|
+
npm notice 1.1kB dist/utilFuncs/tryCatchV2.js
|
|
123
|
+
npm notice 969B dist/utilFuncs/tryCatchV2.js.map
|
|
124
|
+
npm notice 2.5kB dist/WAL.d.ts
|
|
125
|
+
npm notice 1.8kB dist/WAL.d.ts.map
|
|
126
|
+
npm notice 9.1kB dist/WAL.js
|
|
127
|
+
npm notice 8.2kB dist/WAL.js.map
|
|
128
|
+
npm notice 4.4kB lib/auth.ts
|
|
129
|
+
npm notice 3.2kB lib/files.ts
|
|
130
|
+
npm notice 10.5kB lib/filters.ts
|
|
131
|
+
npm notice 42.7kB lib/index.ts
|
|
132
|
+
npm notice 1.3kB lib/insertTypes.ts
|
|
133
|
+
npm notice 963B lib/insertUpdateUtils.ts
|
|
134
|
+
npm notice 876B lib/joinHelpers.ts
|
|
135
|
+
npm notice 4.6kB lib/JSONBSchemaValidation/getJSONBSchemaAsJSONSchema.ts
|
|
136
|
+
npm notice 5.5kB lib/JSONBSchemaValidation/getJSONBSchemaTSTypes.ts
|
|
137
|
+
npm notice 10.3kB lib/JSONBSchemaValidation/JSONBSchema.ts
|
|
138
|
+
npm notice 19.0kB lib/JSONBSchemaValidation/JSONBSchemaValidation.ts
|
|
139
|
+
npm notice 1.1kB lib/JSONBSchemaValidation/utils.ts
|
|
140
|
+
npm notice 6.0kB lib/md5.ts
|
|
141
|
+
npm notice 11.7kB lib/replication.ts
|
|
142
|
+
npm notice 3.9kB lib/selectTypesV2.ts
|
|
143
|
+
npm notice 5.9kB lib/typeTests.ts
|
|
144
|
+
npm notice 179B lib/typeUtils.ts
|
|
145
|
+
npm notice 11.1kB lib/util.ts
|
|
146
|
+
npm notice 121B lib/utilFuncs/includes.ts
|
|
147
|
+
npm notice 85B lib/utilFuncs/index.ts
|
|
148
|
+
npm notice 2.7kB lib/utilFuncs/isEqual.ts
|
|
149
|
+
npm notice 1.1kB lib/utilFuncs/tryCatchV2.ts
|
|
150
|
+
npm notice 8.7kB lib/WAL.ts
|
|
151
|
+
npm notice 1.4kB package.json
|
|
152
|
+
npm notice Tarball Details
|
|
153
|
+
npm notice name: prostgles-types
|
|
154
|
+
npm notice version: 4.0.282
|
|
155
|
+
npm notice filename: prostgles-types-4.0.282.tgz
|
|
156
|
+
npm notice package size: 127.6 kB
|
|
157
|
+
npm notice unpacked size: 566.3 kB
|
|
158
|
+
npm notice shasum: 79f2a12533f40862c5353e0050be13629bc007a7
|
|
159
|
+
npm notice integrity: sha512-cn3e2nYo7S7fh[...]IU6TSazti72Eg==
|
|
160
|
+
npm notice total files: 119
|
|
161
|
+
npm notice
|
|
162
|
+
prostgles-types-4.0.282.tgz
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,wBAAwB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DBSchemaTable, TableSchema } from "prostgles-types";
|
|
2
|
+
import type { TableConfig } from "../TableConfig/TableConfigTypes";
|
|
3
|
+
/** Permissions compiled from publish profiles at startup. */
|
|
4
|
+
export type ClientSchemaProfiles = Record<string, {
|
|
5
|
+
tableSchema: DBSchemaTable[];
|
|
6
|
+
}>;
|
|
7
|
+
export declare const getClientDBGeneratedSchemas: (profiles: ClientSchemaProfiles, tables: TableSchema[], config: TableConfig | undefined) => string;
|
|
8
|
+
export declare const validateClientSchemaName: (name: string) => void;
|
|
9
|
+
//# sourceMappingURL=getClientDBGeneratedSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientDBGeneratedSchemas.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getClientDBGeneratedSchemas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEnE,6DAA6D;AAC7D,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,WAAW,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC,CAAC;AAEpF,eAAO,MAAM,2BAA2B,GACtC,UAAU,oBAAoB,EAC9B,QAAQ,WAAW,EAAE,EACrB,QAAQ,WAAW,GAAG,SAAS,KAC9B,MAgEF,CAAC;AAUF,eAAO,MAAM,wBAAwB,GAAI,MAAM,MAAM,SAKpD,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateClientSchemaName = exports.getClientDBGeneratedSchemas = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const getClientDBGeneratedSchemas = (profiles, tables, config) => {
|
|
6
|
+
const entries = Object.entries(profiles).sort(([a], [b]) => a.localeCompare(b));
|
|
7
|
+
if (!entries.length)
|
|
8
|
+
return "";
|
|
9
|
+
for (const [name, schema] of entries) {
|
|
10
|
+
(0, exports.validateClientSchemaName)(name);
|
|
11
|
+
for (const table of schema.tableSchema) {
|
|
12
|
+
const base = tables.find((t) => t.name === table.name);
|
|
13
|
+
if (!base || table.columns.some((c) => !base.columns.some((b) => b.name === c.name))) {
|
|
14
|
+
throw new Error(`Cannot generate ${name}: unknown table or column in ${table.name}.`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const generate = (name, schemas) => {
|
|
19
|
+
const definitions = tables
|
|
20
|
+
.slice()
|
|
21
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
22
|
+
.flatMap((table) => {
|
|
23
|
+
const published = schemas.map((s) => s.tableSchema.find((t) => t.name === table.name));
|
|
24
|
+
if (!published.some(Boolean))
|
|
25
|
+
return [];
|
|
26
|
+
const inserting = published.filter((t) => t?.publishInfo.insert);
|
|
27
|
+
const tableType = `${constants_1.DB_GENERATED_SCHEMA_NAME}[${JSON.stringify(table.name)}]`;
|
|
28
|
+
const required = [];
|
|
29
|
+
const optional = [];
|
|
30
|
+
const excluded = [];
|
|
31
|
+
for (const column of table.columns.slice().sort((a, b) => a.name.localeCompare(b.name))) {
|
|
32
|
+
const writable = inserting.map((t) => !!t?.columns.find((c) => c.name === column.name)?.insert);
|
|
33
|
+
if (!writable.some(Boolean)) {
|
|
34
|
+
excluded.push(`${JSON.stringify(column.name)}?: never`);
|
|
35
|
+
}
|
|
36
|
+
else if (!writable.every(Boolean) ||
|
|
37
|
+
config?.[table.name]?.syncConfig?.synced_field === column.name) {
|
|
38
|
+
optional.push(column.name);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
required.push(column.name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const input = !inserting.length ? "never" : ([
|
|
45
|
+
required.length ? `Pick<${tableType}["columns"], ${keys(required)}>` : "",
|
|
46
|
+
optional.length ? `Partial<Pick<${tableType}["columns"], ${keys(optional)}>>` : "",
|
|
47
|
+
excluded.length ? `{ ${excluded.join("; ")} }` : "",
|
|
48
|
+
]
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.join(" & ") || "Record<string, never>");
|
|
51
|
+
return [` ${JSON.stringify(table.name)}: ${tableType} & { insertColumns: ${input} };`];
|
|
52
|
+
});
|
|
53
|
+
return `export type ${name} = {\n${definitions.join("\n")}\n};`;
|
|
54
|
+
};
|
|
55
|
+
return [
|
|
56
|
+
"/** Insert access profiles. Row types retain the database schema; runtime permissions still apply. */",
|
|
57
|
+
...entries.map(([name, schema]) => generate(name, [schema])),
|
|
58
|
+
"/** Permissive insert inputs across all supplied profiles; narrow to a named profile for exact inputs. */",
|
|
59
|
+
generate("ClientDBSchema", entries.map(([, schema]) => schema)),
|
|
60
|
+
].join("\n\n");
|
|
61
|
+
};
|
|
62
|
+
exports.getClientDBGeneratedSchemas = getClientDBGeneratedSchemas;
|
|
63
|
+
const keys = (names) => names.map((name) => JSON.stringify(name)).join(" | ");
|
|
64
|
+
const reservedNames = new Set([
|
|
65
|
+
constants_1.DB_GENERATED_SCHEMA_NAME,
|
|
66
|
+
"DBSchema",
|
|
67
|
+
"DBSchemaForInsert",
|
|
68
|
+
"ClientDBSchema",
|
|
69
|
+
]);
|
|
70
|
+
const validateClientSchemaName = (name) => {
|
|
71
|
+
// Requiring a Schema suffix also avoids TypeScript keywords and primitive type names.
|
|
72
|
+
if (!/^[A-Za-z_$][\w$]*Schema$/.test(name) || reservedNames.has(name)) {
|
|
73
|
+
throw new Error(`Invalid client schema name: ${name}. Use a unique name ending in Schema.`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.validateClientSchemaName = validateClientSchemaName;
|
|
77
|
+
//# sourceMappingURL=getClientDBGeneratedSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getClientDBGeneratedSchemas.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getClientDBGeneratedSchemas.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AAOhD,MAAM,2BAA2B,GAAG,CACzC,QAA8B,EAC9B,MAAqB,EACrB,MAA+B,EACvB,EAAE;IACV,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAChF,IAAI,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACrC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC;QAC/B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YACvC,MAAM,IAAI,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,KAAK,CAAC,CAAC;AACxF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,oCAAwB;IACxB,UAAU;IACV,mBAAmB;IACnB,gBAAgB;CACjB,CAAC,CAAC;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,sFAAsF;IACtF,IAAI,CAAC,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,uCAAuC,CAAC,CAAC;IAC9F,CAAC;AACH,CAAC,CAAC;AALW,QAAA,wBAAwB,4BAKnC"}
|
|
@@ -7,8 +7,8 @@ const getColumnConfig_1 = require("../TableConfig/getColumnConfig");
|
|
|
7
7
|
const getLookupTableValues_1 = require("./getLookupTableValues");
|
|
8
8
|
const getColumnTypescriptDefinition = ({ config, tablesOrViews, tableOrView, column, }) => {
|
|
9
9
|
/**
|
|
10
|
-
* Columns that are nullable or have default values can be
|
|
11
|
-
* Non nullable columns with default values cannot
|
|
10
|
+
* Columns that are nullable or have default values can be omitted from an insert
|
|
11
|
+
* Non nullable columns with default values cannot contain null values in an insert so they must contain a valid value or be omitted
|
|
12
12
|
*/
|
|
13
13
|
const dataType = (0, exports.getDataType)({
|
|
14
14
|
config,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type TableSchema } from "prostgles-types";
|
|
2
2
|
import type { TableConfig } from "../TableConfig/TableConfigTypes";
|
|
3
|
-
|
|
3
|
+
import { type ClientSchemaProfiles } from "./getClientDBGeneratedSchemas";
|
|
4
|
+
export declare const getDBGeneratedSchema: ({ config, tablesOrViews, clientSchemas, }: {
|
|
4
5
|
config: TableConfig | undefined;
|
|
5
6
|
tablesOrViews: TableSchema[];
|
|
7
|
+
clientSchemas?: ClientSchemaProfiles;
|
|
6
8
|
}) => string;
|
|
7
9
|
//# sourceMappingURL=getDBGeneratedSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDBGeneratedSchema.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getDBGeneratedSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDBGeneratedSchema.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getDBGeneratedSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAInE,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,+BAA+B,CAAC;AAEvC,eAAO,MAAM,oBAAoB,GAAI,2CAIlC;IACD,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,oBAAoB,CAAC;CACtC,KAAG,MAqEH,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDBGeneratedSchema = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
const prostgles_types_1 = require("prostgles-types");
|
|
5
6
|
const utils_1 = require("../utils/utils");
|
|
6
7
|
const getColumnTypescriptDefinition_1 = require("./getColumnTypescriptDefinition");
|
|
7
8
|
const applyScopeToTableRules_1 = require("../PublishParser/applyScopeToTableRules");
|
|
8
|
-
const
|
|
9
|
+
const getClientDBGeneratedSchemas_1 = require("./getClientDBGeneratedSchemas");
|
|
10
|
+
const getDBGeneratedSchema = ({ config, tablesOrViews, clientSchemas, }) => {
|
|
9
11
|
const tables = [];
|
|
10
12
|
/** Tables and columns are sorted to avoid infinite loops due to changing order */
|
|
11
13
|
tablesOrViews
|
|
@@ -47,7 +49,7 @@ const getDBGeneratedSchema = ({ config, tablesOrViews, }) => {
|
|
|
47
49
|
};\n `);
|
|
48
50
|
});
|
|
49
51
|
return `
|
|
50
|
-
export type
|
|
52
|
+
export type ${constants_1.DB_GENERATED_SCHEMA_NAME} = {
|
|
51
53
|
${tables.join("")}
|
|
52
54
|
}
|
|
53
55
|
|
|
@@ -55,15 +57,15 @@ export type DBGeneratedSchema = {
|
|
|
55
57
|
* Data types as expected when selecting from the database
|
|
56
58
|
* */
|
|
57
59
|
export type DBSchema = {
|
|
58
|
-
[K in keyof
|
|
60
|
+
[K in keyof ${constants_1.DB_GENERATED_SCHEMA_NAME}]: Required<${constants_1.DB_GENERATED_SCHEMA_NAME}[K]["columns"]>;
|
|
59
61
|
};
|
|
60
62
|
|
|
61
63
|
/**
|
|
62
64
|
* Data types as expected when inserting into the database (optional fields might be nullable/with defaults)
|
|
63
65
|
* */
|
|
64
66
|
export type DBSchemaForInsert = {
|
|
65
|
-
[K in keyof
|
|
66
|
-
}
|
|
67
|
+
[K in keyof ${constants_1.DB_GENERATED_SCHEMA_NAME}]: ${constants_1.DB_GENERATED_SCHEMA_NAME}[K]["columns"];
|
|
68
|
+
};${clientSchemas ? "\n" + (0, getClientDBGeneratedSchemas_1.getClientDBGeneratedSchemas)(clientSchemas, tablesOrViews, config) : ""}
|
|
67
69
|
`;
|
|
68
70
|
};
|
|
69
71
|
exports.getDBGeneratedSchema = getDBGeneratedSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDBGeneratedSchema.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getDBGeneratedSchema.ts"],"names":[],"mappings":";;;AAAA,qDAAuE;AAEvE,0CAA+C;AAC/C,mFAAgF;AAChF,oFAAsE;
|
|
1
|
+
{"version":3,"file":"getDBGeneratedSchema.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getDBGeneratedSchema.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,qDAAuE;AAEvE,0CAA+C;AAC/C,mFAAgF;AAChF,oFAAsE;AACtE,+EAGuC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AAc,CAAC,MAAM,EAAE,CAAC;gBAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAU,CAAC;YACxD,CAAC;YACD,OAAO;QACT,CAAC,CAAC;aACD,MAAM,CAAC,2BAAS,CAAC,CACrB,CAAC;QACF,MAAM,eAAe,GACnB,IAAA,yBAAO,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC;QAChF,MAAM,CAAC,IAAI,CAAC,GAAG,IAAA,qBAAa,EAAC,WAAW,CAAC,IAAI,CAAC;gBACpC,IAAI;aACb,GAAG,CACF,CAAC,MAAM,EAAE,EAAE,CAAC;QACZ,IAAA,6DAA6B,EAAC,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,CAChF;aACA,IAAI,CAAC,EAAE,CAAC;;MAET,eAAe;SACZ,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IACL,OAAO;cACK,oCAAwB;IAClC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;;;;;;;gBAOH,oCAAwB,eAAe,oCAAwB;;;;;;;gBAO/D,oCAAwB,MAAM,oCAAwB;IAClE,aAAa,CAAC,CAAC,CAAC,IAAI,GAAG,IAAA,yDAA2B,EAAC,aAAa,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE;CAChG,CAAC;AACF,CAAC,CAAC;AA7EW,QAAA,oBAAoB,wBA6E/B"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PublishParser } from "../PublishParser/PublishParser";
|
|
2
|
+
import type { ClientSchemaProfiles } from "./getClientDBGeneratedSchemas";
|
|
3
|
+
export declare const getPublishSchemas: (publishParser: PublishParser) => Promise<ClientSchemaProfiles | undefined>;
|
|
4
|
+
//# sourceMappingURL=getPublishSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPublishSchemas.d.ts","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getPublishSchemas.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,GAC5B,eAAe,aAAa,KAC3B,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAgC1C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPublishSchemas = void 0;
|
|
4
|
+
const getColumns_1 = require("../DboBuilder/getColumns");
|
|
5
|
+
const getRawInfo_1 = require("../DboBuilder/ViewHandler/getRawInfo");
|
|
6
|
+
const getPublishedTableNames_1 = require("../PublishParser/getPublishedTableNames");
|
|
7
|
+
const getPublishSchemas = async (publishParser) => {
|
|
8
|
+
if (!Array.isArray(publishParser.publish)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const entries = publishParser.publish;
|
|
12
|
+
const profiles = Object.fromEntries(entries.map(({ name }) => [name, { tableSchema: [] }]));
|
|
13
|
+
const { tablesOrViews = [] } = publishParser.prostgles.dboBuilder;
|
|
14
|
+
for (const { name, publish } of entries) {
|
|
15
|
+
const publishObject = publish === "*" ?
|
|
16
|
+
Object.fromEntries(tablesOrViews.map((table) => [table.name, "*"]))
|
|
17
|
+
: (publish ?? {});
|
|
18
|
+
const tableNames = (0, getPublishedTableNames_1.getPublishedTableNames)(publishParser, publishObject);
|
|
19
|
+
for (const tableName of tableNames) {
|
|
20
|
+
const rules = await publishParser.getTableRules({ tableName, clientReq: undefined }, undefined, undefined, publishObject);
|
|
21
|
+
if (!rules || !Object.values(rules).some(Boolean))
|
|
22
|
+
continue;
|
|
23
|
+
const table = publishParser.dbo[tableName];
|
|
24
|
+
profiles[name].tableSchema.push({
|
|
25
|
+
...getRawInfo_1.getRawInfo.call(table, undefined, rules),
|
|
26
|
+
name: tableName,
|
|
27
|
+
columns: await getColumns_1.getRawColumns.call(table, undefined, undefined, rules),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return profiles;
|
|
32
|
+
};
|
|
33
|
+
exports.getPublishSchemas = getPublishSchemas;
|
|
34
|
+
//# sourceMappingURL=getPublishSchemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPublishSchemas.js","sourceRoot":"","sources":["../../lib/DBSchemaBuilder/getPublishSchemas.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,qEAAkE;AAClE,oFAAiF;AAI1E,MAAM,iBAAiB,GAAG,KAAK,EACpC,aAA4B,EACe,EAAE;IAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1C,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC;IACtC,MAAM,QAAQ,GAAyB,MAAM,CAAC,WAAW,CACvD,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC,CACvD,CAAC;IACF,MAAM,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,aAAa,CAAC,SAAS,CAAC,UAAU,CAAC;IAClE,KAAK,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,CAAC;QACxC,MAAM,aAAa,GACjB,OAAO,KAAK,GAAG,CAAC,CAAC;YACf,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;YACrE,CAAC,CAAC,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