prostgles-types 4.0.106 → 4.0.107

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "prostgles-types",
3
- "version": "4.0.106",
3
+ "version": "4.0.107",
4
4
  "description": "",
5
5
  "main": "dist/index_umd.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "directories": {},
8
8
  "scripts": {
9
9
  "start": "tsc --watch",
10
- "test": "npm run build && cd tests && tsc && node index.js",
10
+ "test": "npm run build && node --test dist/*.spec.js",
11
11
  "build": "npm i && rm -rf ./dist/* && tsc && webpack --config webpack.prod.js",
12
12
  "pushpublish": "npm version patch --git-tag-version false && git push && npm publish"
13
13
  },
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "files": ["lib/index.ts"],
2
+ "include": ["lib/**/*"],
3
3
  "compilerOptions": {
4
4
  "baseUrl": ".",
5
5
  "target": "es2020",
@@ -24,5 +24,6 @@
24
24
  "noUncheckedIndexedAccess": true
25
25
  },
26
26
  "exclude": [
27
+ "node_modules"
27
28
  ],
28
29
  }
package/tests/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":""}
package/tests/index.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../dist/util");
4
- const typeTests_1 = require("./typeTests");
5
- const jsonbTest_1 = require("./jsonbTest");
6
- (0, typeTests_1.typeTestsOK)();
7
- (0, jsonbTest_1.jsonbTest)();
8
- let error;
9
- let failed = -1;
10
- const vals = [
11
- { o: "ad awd awd awb", n: "a12b" },
12
- { o: "ab", n: "zzzzzzzzdqw q32e3qz" },
13
- { o: "ab", n: "12ab" },
14
- { o: "ab", n: "a12" },
15
- { o: "", n: "a12b" },
16
- { o: "ab", n: "" },
17
- { o: "ab", n: null },
18
- { o: null, n: "a12b" },
19
- { o: "ab123", n: "ab123" },
20
- ];
21
- vals.map(({ o, n }, i) => {
22
- const patch = (0, util_1.getTextPatch)(o, n);
23
- const unpatched = (0, util_1.unpatchText)(o, patch);
24
- if (unpatched !== n) {
25
- failed = i;
26
- }
27
- });
28
- if (failed > -1) {
29
- error = { msg: "unpatchText failed for:", data: vals[failed] };
30
- }
31
- const w = new util_1.WAL({
32
- id_fields: ["a", "b"],
33
- synced_field: "c",
34
- onSend: async (d) => {
35
- if (d[0].a !== "a" || d[3].a !== "z" || d[2].b !== "zbb") {
36
- error = error || { msg: "WAL sorting failed", data: d };
37
- }
38
- if (error) {
39
- console.error(error);
40
- process.exit(1);
41
- }
42
- else {
43
- console.log("Testing successful");
44
- process.exit(0);
45
- }
46
- },
47
- throttle: 100,
48
- batch_size: 50
49
- });
50
- w.addData([
51
- { current: { a: "a", b: "bbb", c: "1" } },
52
- { current: { a: "e", b: "zbb", c: "1" } },
53
- { current: { a: "e", b: "ebb", c: "1" } },
54
- { current: { a: "z", b: "bbb", c: "1" } }
55
- ]);
56
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AACA,uCAAyE;AAEzE,2CAA0C;AAC1C,2CAAwC;AAExC,IAAA,uBAAW,GAAE,CAAC;AACd,IAAA,qBAAS,GAAE,CAAC;AAEZ,IAAI,KAAU,CAAC;AAEf,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC;AAChB,MAAM,IAAI,GAAG;IACX,EAAE,CAAC,EAAE,gBAAgB,EAAE,CAAC,EAAE,MAAM,EAAE;IAClC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,qBAAqB,EAAE;IACrC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE;IACtB,EAAE,C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IAAI,EAAE,GAAG,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;QACzD,CAAC;QAGD,IAAG,KAAK,EAAC,CAAC;YACR,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;YACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,QAAQ,EAAE,GAAG;IACb,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAEH,CAAC,CAAC,OAAO,CACP;IACE,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAC,EAAE;IACxC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAC,EAAE;IACxC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAC,EAAE;IACxC,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAC,EAAE;CACzC,CACF,CAAC"}
package/tests/index.ts DELETED
@@ -1,69 +0,0 @@
1
- import { strict as assert } from 'assert';
2
- import { getTextPatch, TextPatch, unpatchText, WAL } from "../dist/util";
3
- import { getJSONBSchemaAsJSONSchema } from "../dist/jsonb";
4
- import { typeTestsOK } from "./typeTests";
5
- import { jsonbTest } from "./jsonbTest";
6
-
7
- typeTestsOK();
8
- jsonbTest();
9
-
10
- let error: any;
11
-
12
- let failed = -1;
13
- const vals = [
14
- { o: "ad awd awd awb", n: "a12b" },
15
- { o: "ab", n: "zzzzzzzzdqw q32e3qz" },
16
- { o: "ab", n: "12ab" },
17
- { o: "ab", n: "a12" },
18
- { o: "", n: "a12b" },
19
- { o: "ab", n: "" },
20
- { o: "ab", n: null },
21
- { o: null, n: "a12b" },
22
- { o: "ab123", n: "ab123" },
23
- ];
24
-
25
- vals.map(({ o, n }, i) => {
26
- const patch = getTextPatch(o as any, n as any) as TextPatch;
27
- // console.log(o, patch)
28
- const unpatched = unpatchText(o, patch);
29
- // console.log(o, unpatched, n)
30
- if(unpatched !== n){
31
- failed = i;
32
- }
33
- });
34
-
35
- if(failed > -1) {
36
- error = { msg: "unpatchText failed for:", data: vals[failed] }
37
- }
38
-
39
- /** TEST THIS AT END - will exit process */
40
- const w = new WAL({
41
- id_fields: ["a", "b"],
42
- synced_field: "c",
43
- onSend: async (d) => {
44
-
45
- if(d[0].a !== "a" || d[3].a !== "z" || d[2].b !== "zbb"){
46
- error = error || { msg: "WAL sorting failed", data: d }
47
- }
48
-
49
- /* END */
50
- if(error){
51
- console.error(error);
52
- process.exit(1);
53
- } else {
54
- console.log("Testing successful")
55
- process.exit(0);
56
- }
57
- },
58
- throttle: 100,
59
- batch_size: 50
60
- });
61
-
62
- w.addData(
63
- [
64
- { current: { a: "a", b: "bbb", c: "1"} },
65
- { current: { a: "e", b: "zbb", c: "1"} },
66
- { current: { a: "e", b: "ebb", c: "1"} },
67
- { current: { a: "z", b: "bbb", c: "1"} }
68
- ]
69
- );
@@ -1,2 +0,0 @@
1
- export declare const jsonbTest: () => void;
2
- //# sourceMappingURL=jsonbTest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonbTest.d.ts","sourceRoot":"","sources":["jsonbTest.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,SAAS,YAsBrB,CAAA"}
@@ -1,139 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jsonbTest = void 0;
4
- const jsonb_1 = require("../dist/jsonb");
5
- const assert_1 = require("assert");
6
- const jsonbTest = () => {
7
- const res = (0, jsonb_1.getJSONSchemaObject)({
8
- type: {
9
- scope: {
10
- type: "string[]",
11
- allowedValues: ["a", "b"]
12
- }
13
- }
14
- });
15
- assert_1.strict.deepStrictEqual(res, {
16
- type: "object",
17
- required: ["scope"],
18
- properties: {
19
- scope: {
20
- type: "array",
21
- items: {
22
- type: "string",
23
- enum: ["a", "b"]
24
- }
25
- }
26
- }
27
- });
28
- };
29
- exports.jsonbTest = jsonbTest;
30
- const jsonS = (0, jsonb_1.getJSONBSchemaAsJSONSchema)("tjson", "json", { type: {
31
- a: { type: "boolean" },
32
- arr: { enum: ["1", "2", "3"] },
33
- arr1: { enum: [1, 2, 3] },
34
- arr2: { type: "integer[]" },
35
- arrStr: { type: "string[]", optional: true, nullable: true },
36
- o: { optional: true, nullable: true, oneOfType: [
37
- { o1: "integer" },
38
- { o2: "boolean" }
39
- ] },
40
- customTables: { optional: true, arrayOfType: {
41
- tableName: "string",
42
- select: {
43
- "optional": true,
44
- "oneOf": [
45
- "boolean",
46
- { "type": { fields: "string[]" } }
47
- ]
48
- }
49
- }
50
- }
51
- } });
52
- assert_1.strict.deepEqual(jsonS, {
53
- $id: 'tjson.json',
54
- $schema: 'https://json-schema.org/draft/2020-12/schema',
55
- type: 'object',
56
- required: ['a', 'arr', 'arr1', 'arr2'],
57
- properties: {
58
- a: { type: 'boolean' },
59
- arr: {
60
- type: 'string', enum: ['1', '2', '3']
61
- },
62
- arr1: {
63
- type: 'number', enum: [1, 2, 3]
64
- },
65
- arr2: { type: 'array', items: { type: 'integer' } },
66
- arrStr: {
67
- oneOf: [
68
- { type: 'array', items: { type: 'string' } },
69
- { type: 'null' }
70
- ]
71
- },
72
- o: {
73
- oneOf: [
74
- { type: "object", required: ["o1"], properties: { o1: { type: 'integer' } } },
75
- { type: "object", required: ["o2"], properties: { o2: { type: 'boolean' } } },
76
- { type: 'null' }
77
- ]
78
- },
79
- customTables: {
80
- type: "array",
81
- items: {
82
- type: "object",
83
- required: ["tableName"],
84
- properties: {
85
- tableName: { type: "string" },
86
- select: {
87
- oneOf: [
88
- { type: "boolean" },
89
- {
90
- type: "object",
91
- required: ["fields"],
92
- properties: {
93
- fields: { type: "array", items: { type: "string" } }
94
- }
95
- }
96
- ]
97
- }
98
- }
99
- }
100
- }
101
- }
102
- });
103
- assert_1.strict.deepEqual((0, jsonb_1.getJSONBSchemaAsJSONSchema)("tjson", "status", {
104
- nullable: true,
105
- oneOfType: [
106
- { ok: { type: "string" } },
107
- { err: { type: "string" } },
108
- {
109
- loading: { type: {
110
- loaded: { type: "number" },
111
- total: { type: "number" }
112
- }
113
- }
114
- }
115
- ]
116
- }), {
117
- $id: 'tjson.status',
118
- $schema: 'https://json-schema.org/draft/2020-12/schema',
119
- oneOf: [
120
- { type: "object", required: ["ok"], properties: { ok: { type: 'string' } } },
121
- { type: "object", required: ["err"], properties: { err: { type: 'string' } } },
122
- {
123
- type: "object",
124
- required: ["loading"],
125
- properties: {
126
- loading: {
127
- required: ["loaded", "total"],
128
- properties: {
129
- loaded: { type: 'number' },
130
- total: { type: 'number' }
131
- },
132
- type: 'object'
133
- }
134
- }
135
- },
136
- { type: "null" }
137
- ],
138
- });
139
- //# sourceMappingURL=jsonbTest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonbTest.js","sourceRoot":"","sources":["jsonbTest.ts"],"names":[],"mappings":";;;AACA,yCAAgF;AAChF,mCAA0C;AAEnC,MAAM,SAAS,GAAG,GAAG,EAAE;IAC5B,MAAM,GAAG,GAAG,IAAA,2BAAmB,EAAC;QAC9B,IAAI,EAAE;YACJ,KAAK,EAAE;gBACL,IAAI,EAAE,UAAU;gBAChB,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC;aAC1B;SACF;KACF,CAAC,CAAC;IACH,eAAM,CAAC,eAAe,CAAC,GAAG,EAAE;QAC1B,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,CAAC,OAAO,CAAC;QACnB,UAAU,EAAE;YACV,KAAK,EAAE;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E,IAAI,EAAE,QAAQ,EAAE;wBAC1B,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAC;qBACzB;oBACD,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;QACD,EAAE,IAAI,EAAE,MAAM,EAAE;KACjB;CAEF,CACF,CAAC"}
@@ -1,146 +0,0 @@
1
-
2
- import { getJSONBSchemaAsJSONSchema, getJSONSchemaObject } from "../dist/jsonb";
3
- import { strict as assert } from 'assert';
4
-
5
- export const jsonbTest = () => {
6
- const res = getJSONSchemaObject({
7
- type: {
8
- scope: {
9
- type: "string[]",
10
- allowedValues: ["a", "b"]
11
- }
12
- }
13
- });
14
- assert.deepStrictEqual(res, {
15
- type: "object",
16
- required: ["scope"],
17
- properties: {
18
- scope: {
19
- type: "array",
20
- items: {
21
- type: "string",
22
- enum: ["a", "b"]
23
- }
24
- }
25
- }
26
- });
27
- }
28
-
29
- const jsonS = getJSONBSchemaAsJSONSchema("tjson", "json", { type: {
30
- a: { type: "boolean" },
31
- arr: { enum: ["1", "2", "3"] },
32
- arr1: { enum: [1, 2, 3] },
33
- arr2: { type: "integer[]" },
34
- arrStr: { type: "string[]", optional: true, nullable: true },
35
- o: { optional: true, nullable: true, oneOfType: [
36
- { o1: "integer" },
37
- { o2: "boolean" }
38
- ] },
39
- customTables: { optional: true, arrayOfType: {
40
- tableName: "string",
41
- select: {
42
- "optional": true,
43
- "oneOf": [
44
- "boolean",
45
- { "type": { fields: "string[]" } }
46
- ]
47
- }
48
- }
49
- }
50
- }});
51
-
52
- assert.deepEqual(
53
- jsonS,
54
- {
55
- $id: 'tjson.json',
56
- $schema: 'https://json-schema.org/draft/2020-12/schema',
57
- // title: 'json',
58
- type: 'object',
59
- required: [ 'a', 'arr', 'arr1', 'arr2' ],
60
- properties: {
61
- a: { type: 'boolean' },
62
- arr: {
63
- type: 'string', enum: [ '1', '2', '3' ]
64
- },
65
- arr1: {
66
- type: 'number', enum: [ 1, 2, 3 ]
67
- },
68
- arr2: { type: 'array', items: { type: 'integer' } },
69
- arrStr: {
70
- oneOf: [
71
- { type: 'array', items: { type: 'string' } },
72
- { type: 'null' }
73
- ]
74
- },
75
- o: {
76
- oneOf: [
77
- { type: "object", required: ["o1"], properties: {o1: { type: 'integer' } } },
78
- { type: "object", required: ["o2"], properties: {o2: { type: 'boolean' } } },
79
- { type: 'null' }
80
- ]
81
- },
82
- customTables: {
83
- type: "array",
84
- items: {
85
- type: "object",
86
- required: [ "tableName" ],
87
- properties: {
88
- tableName: { type: "string" },
89
- select: {
90
- oneOf: [
91
- { type: "boolean" },
92
- {
93
- type: "object",
94
- required: [ "fields" ],
95
- properties: {
96
- fields: { type: "array", items: { type: "string" } }
97
- }
98
- }
99
- ]
100
- }
101
- }
102
- }
103
- }
104
- }
105
- }
106
- );
107
-
108
- assert.deepEqual(
109
- getJSONBSchemaAsJSONSchema("tjson", "status", {
110
- nullable: true,
111
- oneOfType: [
112
- { ok: { type: "string" } },
113
- { err: { type: "string" } },
114
- {
115
- loading: { type: {
116
- loaded: { type: "number" },
117
- total: { type: "number" }
118
- }
119
- }
120
- }
121
- ]
122
- }),{
123
- $id: 'tjson.status',
124
- $schema: 'https://json-schema.org/draft/2020-12/schema',
125
- oneOf: [
126
- { type: "object", required: ["ok"], properties: { ok: { type: 'string' } } },
127
- { type: "object", required: ["err"], properties: { err: { type: 'string' } } },
128
- {
129
- type: "object",
130
- required: ["loading"],
131
- properties: {
132
- loading: {
133
- required: ["loaded", "total"],
134
- properties: {
135
- loaded: { type: 'number' },
136
- total: { type: 'number'}
137
- },
138
- type: 'object'
139
- }
140
- }
141
- },
142
- { type: "null" }
143
- ],
144
- // title: 'status'
145
- }
146
- );
@@ -1,11 +0,0 @@
1
- {
2
- "name": "tests",
3
- "version": "1.0.0",
4
- "description": "",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "author": "",
10
- "license": "ISC"
11
- }
@@ -1,27 +0,0 @@
1
- {
2
- "files": ["./index.ts"],
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "target": "es2020",
6
- "lib": [
7
- "es2019"
8
- ],
9
- "strict": true,
10
- "module": "commonjs",
11
- "removeComments": true,
12
- "sourceMap": true,
13
- "rootDir": ".",
14
- "outDir": ".",
15
- "moduleResolution": "node",
16
- "allowSyntheticDefaultImports": true,
17
- "resolveJsonModule": true,
18
- // "outFile": "bundle.js",
19
- // "moduleResolution": "node"
20
- "skipDefaultLibCheck": true,
21
- "declaration": true,
22
- "declarationMap": true,
23
- "ignoreDeprecations": "5.0",
24
- },
25
- "exclude": [
26
- ],
27
- }
@@ -1,2 +0,0 @@
1
- export declare const typeTestsOK: () => void;
2
- //# sourceMappingURL=typeTests.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeTests.d.ts","sourceRoot":"","sources":["typeTests.ts"],"names":[],"mappings":"AAqOA,eAAO,MAAM,WAAW,YAAW,CAAC"}
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.typeTestsOK = void 0;
4
- (async () => {
5
- const dbo = 1;
6
- const tableHandler = dbo.tbl1;
7
- const params = {
8
- select: {
9
- "*": 1,
10
- bd: { $max: ["b"] },
11
- joined_table: { ids: { "$array_agg": ["joined_field"] } }
12
- }
13
- };
14
- const f = {
15
- $and: [
16
- { a: "d", num: { ">": 232 } },
17
- { "num.$eq": 2, }
18
- ]
19
- };
20
- if (tableHandler) {
21
- const newRow = await tableHandler.insert?.({ h: 2, c: 1 }, { returning: { b: 1, c: 1 } });
22
- newRow.b;
23
- newRow.c;
24
- newRow.h;
25
- const row = await tableHandler.findOne?.({ "c.$nin": [2] }, { select: { b: 0 } });
26
- row?.c;
27
- row?.h;
28
- const query = await tableHandler.find?.({ h: 2 }, { returnType: "statement" });
29
- query.toUpperCase();
30
- row.b;
31
- const vals = await tableHandler.find?.({ "c.$nin": [2] }, { returnType: "values" });
32
- const vals2 = await tableHandler.find?.({ "c.$nin": [2] }, { select: { h: 1 }, returnType: "values" });
33
- vals2[0]?.toExponential();
34
- const valsOptional = await tableHandler.find?.({}, { select: { b: 1 }, returnType: "values" });
35
- const starSelect = await tableHandler.find?.({}, { select: { "*": 1, bd: { $max: ["b"] }, joined_table: { ids: { "$array_agg": ["joined_field"] } } } });
36
- starSelect[0].bd;
37
- starSelect[0].joined_table.at(0);
38
- row.b;
39
- tableHandler.subscribe({ h: 2 }, { select: { b: 1 } }, async (rows) => {
40
- const row = rows[0];
41
- row.b;
42
- row.c;
43
- });
44
- tableHandler.subscribeOne({ h: 2 }, { select: { b: 0 } }, async (row) => {
45
- row.b;
46
- row.c;
47
- row?.c;
48
- });
49
- }
50
- const s1 = {
51
- val: { $template_string: ["$template_string"] }
52
- };
53
- const sqlHandler = undefined;
54
- if (sqlHandler) {
55
- const full = await sqlHandler("SELECT 1", {});
56
- full.rows.flatMap;
57
- full.fields.find(f => f.tsDataType === "string");
58
- const value = await sqlHandler("SELECT 1", {}, { returnType: "value" });
59
- value;
60
- const values = await sqlHandler("SELECT 1", {}, { returnType: "values" });
61
- values.flatMap;
62
- const row = await sqlHandler("SELECT 1", {}, { returnType: "row" });
63
- row?.dhawjpeojfgrdfhoeisj;
64
- const rows = await sqlHandler("SELECT 1", {}, { returnType: "rows" });
65
- rows.flatMap;
66
- const handles = await sqlHandler("SELECT 1", {}, { returnType: "noticeSubscription" });
67
- handles.addListener;
68
- handles.socketChannel;
69
- handles.socketUnsubChannel;
70
- const listenHandlesOrData = await sqlHandler("SELECT 1", {}, { allowListen: true });
71
- if ("command" in listenHandlesOrData) {
72
- listenHandlesOrData.command;
73
- listenHandlesOrData.duration;
74
- }
75
- else {
76
- listenHandlesOrData.command;
77
- handles.addListener;
78
- handles.socketChannel;
79
- handles.socketUnsubChannel;
80
- }
81
- }
82
- const db = 1;
83
- const s = { a: 1 };
84
- const s2 = { a: 1, zz: 1 };
85
- const s22 = { a: 1, zz: { $max: ["c"] } };
86
- const s3 = { a: 1, cc: "2" };
87
- const s33 = { a: 1, c: "$max" };
88
- db.view1.find({ "c1.$in": ["2", new Date()] }, { select: { c1: 1, c2: 1 } });
89
- db.table1.insert({ c1: "2" }, { returning: { c1: 1, c2: "func", dwad: { dwada: [] } } });
90
- db.table1.update;
91
- db.table12.update;
92
- db.table1.find;
93
- const result = await db.table2.update({}, { c1: "" }, { returning: "*" });
94
- result?.at(0)?.c2 ?? 0 + 2;
95
- const ef = {
96
- $existsJoined: {
97
- tbl11: {}
98
- }
99
- };
100
- const emptyExists = {
101
- $existsJoined: {
102
- tbl1: {}
103
- }
104
- };
105
- });
106
- const typeTestsOK = () => { };
107
- exports.typeTestsOK = typeTestsOK;
108
- //# sourceMappingURL=typeTests.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeTests.js","sourceRoot":"","sources":["typeTests.ts"],"names":[],"mappings":";;;AAMC,CAAC,KAAK,IAAI,EAAE;IAsBX,MAAM,GAAG,GAA2B,CAAQ,CAAC;IAE7C,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC;IAC9B,MAAM,MAAM,GAA6C;QACvD,MAAM,EAAE;YACN,GAAG,EAAE,CAAC;YACN,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE;YACnB,YAAY,EAAE,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE;SAC1D;KACF,CAAA;IAED,MAAM,CAAC,GAAsD;QAC3D,IAAI,EAAE;YACJ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;YAC7B,EAAE,SAAS,EAAE,CAAC,GAAI;SACnB;KACF,CAAC;IAEF,IAAG,YAAY,EAAC,CAAC;QACf,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE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,CAAC;IAC1E,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IAwB3B,MAAM,EAAE,GAA+B;QACrC,aAAa,EAAE;YAEb,KAAK,EAAE,EAGN;SACF;KACF,CAAA;IAED,MAAM,WAAW,GAA+B;QAC9C,aAAa,EAAE;YACb,IAAI,EAAE,EAAG;SACV;KACF,CAAA;AACH,CAAC,CAAC,CAAC;AAEI,MAAM,WAAW,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAvB,QAAA,WAAW,eAAY"}
@@ -1,233 +0,0 @@
1
-
2
- import type { TableHandler, SQLHandler, FullFilter, DBHandler, Select, SelectTyped, ExistsFilter, AnyObject, SelectParams, DBSchema, ViewHandler } from "../dist/index";
3
-
4
- /**
5
- * Test select/return type inference
6
- */
7
- (async () => {
8
-
9
- type DBOFullyTyped<Schema = void> = Schema extends DBSchema ? {
10
- [tov_name in keyof Schema]: Schema[tov_name]["is_view"] extends true ?
11
- ViewHandler<Schema[tov_name]["columns"], Schema> :
12
- TableHandler<Schema[tov_name]["columns"], Schema>
13
- } : Record<string, ViewHandler | TableHandler>;
14
-
15
- type GSchema = {
16
- tbl1: {
17
- is_view: false,
18
- columns: {
19
- h: number;
20
- b?: number;
21
- c?: string;
22
- },
23
- delete: true,
24
- select: true,
25
- insert: true,
26
- update: true,
27
- }
28
- };
29
- const dbo: DBOFullyTyped<GSchema> = 1 as any;
30
- // type SchemaDef = { h: number; b?: number; c?: number; }
31
- const tableHandler = dbo.tbl1; //: TableHandler<TableDef> = undefined as any;
32
- const params: SelectParams<GSchema["tbl1"]["columns"]> = {
33
- select: {
34
- "*": 1,
35
- bd: { $max: ["b"] },
36
- joined_table: { ids: { "$array_agg": ["joined_field"] } }
37
- }
38
- }
39
-
40
- const f: FullFilter<{ a: string | null; num: number }, {}> = {
41
- $and: [
42
- { a: "d", num: { ">": 232 } },
43
- { "num.$eq": 2, }
44
- ]
45
- };
46
-
47
- if(tableHandler){
48
- const newRow = await tableHandler.insert?.({ h: 2, c: 1 }, { returning: { b: 1, c: 1 } });
49
- newRow.b;
50
- newRow.c;
51
-
52
- //@ts-expect-error
53
- newRow.h;
54
-
55
- // const f: FullFilter<Partial<{ a: number; s: string}>> = { }
56
- const row = await tableHandler.findOne?.({ "c.$nin": [2] }, { select: {b: 0} });
57
- row?.c;
58
- row?.h;
59
-
60
-
61
- const query = await tableHandler.find?.({ h: 2 }, { returnType: "statement" });
62
- query.toUpperCase();
63
-
64
- //@ts-expect-error
65
- row.b;
66
-
67
- const vals = await tableHandler.find?.({ "c.$nin": [2] }, { returnType: "values" });
68
- const vals2 = await tableHandler.find?.({ "c.$nin": [2] }, { select: { h: 1 }, returnType: "values" });
69
- vals2[0]?.toExponential();
70
-
71
- const valsOptional = await tableHandler.find?.({ }, { select: { b: 1 }, returnType: "values" });
72
- const starSelect = await tableHandler.find?.({ }, { select: { "*": 1, bd: { $max: ["b"] }, joined_table: { ids: { "$array_agg": ["joined_field"] } } } });
73
-
74
- starSelect[0].bd
75
- starSelect[0].joined_table.at(0)
76
-
77
- //@ts-expect-error
78
- row.b;
79
-
80
- tableHandler.subscribe({ h: 2 }, { select: { b: 1 }}, async rows => {
81
- const row = rows[0];
82
- row.b;
83
-
84
- //@ts-expect-error
85
- row.c;
86
- });
87
-
88
- tableHandler.subscribeOne({ h: 2 }, { select: { b: 0 }}, async row => {
89
-
90
- //@ts-expect-error
91
- row.b;
92
-
93
- //@ts-expect-error
94
- row.c;
95
-
96
- row?.c;
97
- });
98
- }
99
- const s1: Select<AnyObject> = {
100
- val: { $template_string: ["$template_string"] }
101
- }
102
-
103
-
104
- const sqlHandler: SQLHandler = undefined as any;
105
- if(sqlHandler){
106
-
107
- const full = await sqlHandler("SELECT 1", {});
108
- full.rows.flatMap;
109
- full.fields.find(f => f.tsDataType === "string");
110
-
111
- const value = await sqlHandler("SELECT 1", {}, { returnType: "value" });
112
- value;
113
-
114
- const values = await sqlHandler("SELECT 1", {}, { returnType: "values" });
115
- values.flatMap
116
-
117
- const row = await sqlHandler("SELECT 1", {}, { returnType: "row" });
118
- row?.dhawjpeojfgrdfhoeisj;
119
-
120
- const rows = await sqlHandler("SELECT 1", {}, { returnType: "rows" });
121
- rows.flatMap
122
-
123
-
124
- const handles = await sqlHandler("SELECT 1", {}, { returnType: "noticeSubscription" });
125
- <Function>handles.addListener;
126
- <string>handles.socketChannel;
127
- <string>handles.socketUnsubChannel;
128
-
129
- const listenHandlesOrData = await sqlHandler("SELECT 1", {}, { allowListen: true });
130
-
131
- if("command" in listenHandlesOrData){
132
- <string>listenHandlesOrData.command;
133
- <number>listenHandlesOrData.duration;
134
-
135
- } else {
136
-
137
- // @ts-expect-error
138
- <string>listenHandlesOrData.command;
139
-
140
- <Function>handles.addListener;
141
- <string>handles.socketChannel;
142
- <string>handles.socketUnsubChannel;
143
- }
144
- }
145
-
146
- const db: DBHandler<{
147
- table1: {
148
- select: true;
149
- insert: true;
150
- update: false;
151
- columns: { c1: string; c2?: number }
152
- };
153
- view1: {
154
- is_view: true
155
- columns: { c1: string; c2: number }
156
- };
157
- table2: {
158
- update: true;
159
- columns: { c1: string; c2?: number }
160
- };
161
- }> = 1 as any;
162
- // const v = await db.sql<{ c: string }>(``)
163
- const s: SelectTyped<{ a: number; c: string } > = { a: 1 }
164
-
165
- // @ts-expect-error
166
- const s2: Select<{ a: number; c: string }, {}> = { a: 1 , zz: 1 }
167
-
168
- // Correct function
169
- const s22: Select<{ a: number; c: string }, {}> = { a: 1 , zz: { $max: ["c"] } }
170
-
171
- // Quick string func notation can only be used against existing column names
172
- // @ts-expect-error
173
- const s3: Select<{ a: number; c: string }, {}> = { a: 1 , cc: "2" }
174
-
175
- const s33: Select<{ a: number; c: string }, {}> = { a: 1 , c: "$max" }
176
-
177
- db.view1.find({ "c1.$in": ["2", new Date()] }, { select: { c1: 1, c2: 1 } });
178
- db.table1.insert({ c1: "2" }, { returning: { c1: 1, c2: "func", dwad: { dwada: [] } } });
179
-
180
- //@ts-expect-error
181
- db.table1.update
182
-
183
- //@ts-expect-error
184
- db.table12.update
185
-
186
- db.table1.find;
187
-
188
- const result = await db.table2.update({}, { c1: "" }, { returning: "*" });
189
- result?.at(0)?.c2 ?? 0 + 2;
190
-
191
-
192
- type SampleSchema = {
193
- tbl1: {
194
- columns: {
195
- col1: number;
196
- col2: string | null
197
- }
198
- }
199
- tbl11: {
200
- columns: {
201
- col11: number;
202
- col21: string | null
203
- }
204
- }
205
- }
206
-
207
- // const ff: FullFilter<SampleSchema["tbl1"]["columns"], SampleSchema> = {
208
- // AnyObject
209
- // }
210
-
211
-
212
-
213
- const ef: ExistsFilter<SampleSchema> = {
214
- $existsJoined: {
215
- // tbl1: {"col1.$eq": 1 }
216
- tbl11: {
217
- // "col11.$eq": 1,
218
- // col11: { "=": 1, $between: [1, 2] }
219
- }
220
- }
221
- }
222
-
223
- const emptyExists: ExistsFilter<SampleSchema> = {
224
- $existsJoined: {
225
- tbl1: { }
226
- }
227
- }
228
- });
229
-
230
- export const typeTestsOK = () => {};
231
-
232
-
233
-