shutro 0.0.0-stage → 0.2.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 (165) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -2
  3. package/dist/audit/index.d.ts +59 -0
  4. package/dist/audit/index.js +96 -0
  5. package/dist/cli/bin.d.ts +2 -0
  6. package/dist/cli/bin.js +11 -0
  7. package/dist/cli/cli.d.ts +10 -0
  8. package/dist/cli/cli.js +164 -0
  9. package/dist/cli/config.d.ts +18 -0
  10. package/dist/cli/config.js +49 -0
  11. package/dist/cli/errors.d.ts +16 -0
  12. package/dist/cli/errors.js +23 -0
  13. package/dist/cli/generate/generate.d.ts +33 -0
  14. package/dist/cli/generate/generate.js +84 -0
  15. package/dist/cli/generate/render.d.ts +23 -0
  16. package/dist/cli/generate/render.js +249 -0
  17. package/dist/cli/index.d.ts +12 -0
  18. package/dist/cli/index.js +12 -0
  19. package/dist/cli/init.d.ts +2 -0
  20. package/dist/cli/init.js +65 -0
  21. package/dist/cli/inspect.d.ts +10 -0
  22. package/dist/cli/inspect.js +82 -0
  23. package/dist/cli/packages.d.ts +6 -0
  24. package/dist/cli/packages.js +6 -0
  25. package/dist/cli/project.d.ts +18 -0
  26. package/dist/cli/project.js +39 -0
  27. package/dist/cli/resolve.d.ts +2 -0
  28. package/dist/cli/resolve.js +28 -0
  29. package/dist/core/compute/graph.d.ts +52 -0
  30. package/dist/core/compute/graph.js +162 -0
  31. package/dist/core/data/data.d.ts +59 -0
  32. package/dist/core/data/data.js +119 -0
  33. package/dist/core/data/load.d.ts +37 -0
  34. package/dist/core/data/load.js +236 -0
  35. package/dist/core/env/env.d.ts +468 -0
  36. package/dist/core/env/env.js +916 -0
  37. package/dist/core/env/identity.d.ts +43 -0
  38. package/dist/core/env/identity.js +65 -0
  39. package/dist/core/env/inspector.d.ts +55 -0
  40. package/dist/core/env/inspector.js +85 -0
  41. package/dist/core/env/time.d.ts +12 -0
  42. package/dist/core/env/time.js +38 -0
  43. package/dist/core/errors.d.ts +256 -0
  44. package/dist/core/errors.js +360 -0
  45. package/dist/core/events/events.d.ts +44 -0
  46. package/dist/core/events/events.js +58 -0
  47. package/dist/core/events/workers.d.ts +56 -0
  48. package/dist/core/events/workers.js +155 -0
  49. package/dist/core/index.d.ts +51 -0
  50. package/dist/core/index.js +42 -0
  51. package/dist/core/model/company.d.ts +6 -0
  52. package/dist/core/model/company.js +31 -0
  53. package/dist/core/model/faces.d.ts +42 -0
  54. package/dist/core/model/faces.js +1 -0
  55. package/dist/core/model/field.d.ts +479 -0
  56. package/dist/core/model/field.js +461 -0
  57. package/dist/core/model/generated.d.ts +77 -0
  58. package/dist/core/model/generated.js +1 -0
  59. package/dist/core/model/id.d.ts +33 -0
  60. package/dist/core/model/id.js +4 -0
  61. package/dist/core/model/model.d.ts +387 -0
  62. package/dist/core/model/model.js +566 -0
  63. package/dist/core/model/partition.d.ts +31 -0
  64. package/dist/core/model/partition.js +71 -0
  65. package/dist/core/model/related.d.ts +17 -0
  66. package/dist/core/model/related.js +60 -0
  67. package/dist/core/model/typed.d.ts +107 -0
  68. package/dist/core/model/typed.js +46 -0
  69. package/dist/core/money/currency.d.ts +39 -0
  70. package/dist/core/money/currency.js +37 -0
  71. package/dist/core/money/decimal.d.ts +26 -0
  72. package/dist/core/money/decimal.js +51 -0
  73. package/dist/core/money/fx.d.ts +68 -0
  74. package/dist/core/money/fx.js +124 -0
  75. package/dist/core/money/money.d.ts +84 -0
  76. package/dist/core/money/money.js +173 -0
  77. package/dist/core/money/quantity.d.ts +67 -0
  78. package/dist/core/money/quantity.js +108 -0
  79. package/dist/core/money/rounding.d.ts +11 -0
  80. package/dist/core/money/rounding.js +12 -0
  81. package/dist/core/recordset/aggregate.d.ts +22 -0
  82. package/dist/core/recordset/aggregate.js +258 -0
  83. package/dist/core/recordset/audit.d.ts +33 -0
  84. package/dist/core/recordset/audit.js +262 -0
  85. package/dist/core/recordset/compute.d.ts +36 -0
  86. package/dist/core/recordset/compute.js +414 -0
  87. package/dist/core/recordset/constraints.d.ts +9 -0
  88. package/dist/core/recordset/constraints.js +61 -0
  89. package/dist/core/recordset/domain.d.ts +31 -0
  90. package/dist/core/recordset/domain.js +300 -0
  91. package/dist/core/recordset/onchange.d.ts +43 -0
  92. package/dist/core/recordset/onchange.js +240 -0
  93. package/dist/core/recordset/recordset.d.ts +110 -0
  94. package/dist/core/recordset/recordset.js +789 -0
  95. package/dist/core/recordset/relations.d.ts +15 -0
  96. package/dist/core/recordset/relations.js +13 -0
  97. package/dist/core/recordset/rls.d.ts +15 -0
  98. package/dist/core/recordset/rls.js +108 -0
  99. package/dist/core/recordset/security.d.ts +56 -0
  100. package/dist/core/recordset/security.js +269 -0
  101. package/dist/core/recordset/sequences.d.ts +31 -0
  102. package/dist/core/recordset/sequences.js +154 -0
  103. package/dist/core/recordset/source.d.ts +9 -0
  104. package/dist/core/recordset/source.js +19 -0
  105. package/dist/core/recordset/sqlErrors.d.ts +6 -0
  106. package/dist/core/recordset/sqlErrors.js +39 -0
  107. package/dist/core/recordset/transitions.d.ts +10 -0
  108. package/dist/core/recordset/transitions.js +80 -0
  109. package/dist/core/recordset/types.d.ts +415 -0
  110. package/dist/core/recordset/types.js +8 -0
  111. package/dist/core/recordset/values.d.ts +33 -0
  112. package/dist/core/recordset/values.js +177 -0
  113. package/dist/core/recordset/writes.d.ts +42 -0
  114. package/dist/core/recordset/writes.js +786 -0
  115. package/dist/core/registry/ddl.d.ts +31 -0
  116. package/dist/core/registry/ddl.js +174 -0
  117. package/dist/core/registry/extension.d.ts +94 -0
  118. package/dist/core/registry/extension.js +90 -0
  119. package/dist/core/registry/module.d.ts +89 -0
  120. package/dist/core/registry/module.js +98 -0
  121. package/dist/core/registry/registry.d.ts +130 -0
  122. package/dist/core/registry/registry.js +591 -0
  123. package/dist/core/security/runtime.d.ts +102 -0
  124. package/dist/core/security/runtime.js +232 -0
  125. package/dist/driver-pg/driver.d.ts +88 -0
  126. package/dist/driver-pg/driver.js +177 -0
  127. package/dist/driver-pg/errors.d.ts +72 -0
  128. package/dist/driver-pg/errors.js +182 -0
  129. package/dist/driver-pg/index.d.ts +7 -0
  130. package/dist/driver-pg/index.js +7 -0
  131. package/dist/i18n/index.d.ts +25 -0
  132. package/dist/i18n/index.js +51 -0
  133. package/dist/migrate/apply.d.ts +78 -0
  134. package/dist/migrate/apply.js +167 -0
  135. package/dist/migrate/catalog.d.ts +10 -0
  136. package/dist/migrate/catalog.js +122 -0
  137. package/dist/migrate/diff.d.ts +98 -0
  138. package/dist/migrate/diff.js +160 -0
  139. package/dist/migrate/errors.d.ts +21 -0
  140. package/dist/migrate/errors.js +31 -0
  141. package/dist/migrate/index.d.ts +18 -0
  142. package/dist/migrate/index.js +18 -0
  143. package/dist/migrate/render.d.ts +5 -0
  144. package/dist/migrate/render.js +101 -0
  145. package/dist/migrate/schema.d.ts +61 -0
  146. package/dist/migrate/schema.js +233 -0
  147. package/dist/security/index.d.ts +147 -0
  148. package/dist/security/index.js +278 -0
  149. package/dist/sequence/index.d.ts +63 -0
  150. package/dist/sequence/index.js +106 -0
  151. package/dist/sql/ast.d.ts +49 -0
  152. package/dist/sql/ast.js +47 -0
  153. package/dist/sql/builder/builder.d.ts +215 -0
  154. package/dist/sql/builder/builder.js +308 -0
  155. package/dist/sql/builder/expression.d.ts +80 -0
  156. package/dist/sql/builder/expression.js +126 -0
  157. package/dist/sql/compile.d.ts +18 -0
  158. package/dist/sql/compile.js +41 -0
  159. package/dist/sql/errors.d.ts +13 -0
  160. package/dist/sql/errors.js +16 -0
  161. package/dist/sql/index.d.ts +19 -0
  162. package/dist/sql/index.js +19 -0
  163. package/dist/sql/tag.d.ts +47 -0
  164. package/dist/sql/tag.js +123 -0
  165. package/package.json +82 -4
@@ -0,0 +1,47 @@
1
+ import { type SqlFragment } from './ast.js';
2
+ /** The `sql` tagged template and its helpers. */
3
+ export interface SqlTag {
4
+ /**
5
+ * Builds a SQL fragment. Template text is SQL; every `${value}` becomes a bound parameter (`$n`), except
6
+ * fragments, which are inlined. Values never become SQL text.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * sql`SELECT ${sql.id('name')} FROM ${sql.id('res_partner')} WHERE ${sql.id('id')} = ${partnerId}`
11
+ * // → { text: 'SELECT "name" FROM "res_partner" WHERE "id" = $1', params: [partnerId] }
12
+ * ```
13
+ * @throws {SqlError} `SQL_NOT_A_TEMPLATE` if not called as a tagged template; `SQL_UNDEFINED_PARAM`,
14
+ * `SQL_INVALID_NUMBER` or `SQL_INVALID_PARAM` for values that can't be sent.
15
+ */
16
+ (strings: TemplateStringsArray, ...values: readonly unknown[]): SqlFragment;
17
+ /**
18
+ * A quoted identifier, optionally qualified: `sql.id('so', 'amount_total')` → `"so"."amount_total"`.
19
+ * Each part must be lower-case snake_case, at most 63 characters.
20
+ * @throws {SqlError} `SQL_INVALID_IDENTIFIER`
21
+ */
22
+ id(...parts: readonly string[]): SqlFragment;
23
+ /**
24
+ * A parameter with an explicit cast: `sql.param('1.50', 'numeric')` → `$1::numeric`.
25
+ * @throws {SqlError} `SQL_INVALID_TYPE`, or the value errors of the tag.
26
+ */
27
+ param(value: unknown, type: string): SqlFragment;
28
+ /**
29
+ * One array parameter with an element type: `sql.array(ids, 'bigint')` → `$1::bigint[]`. The SQL text stays the same
30
+ * whatever the array length (stable prepared statements, RFC 0005 R6).
31
+ * @throws {SqlError} `SQL_INVALID_PARAM` if `values` is not an array, `SQL_INVALID_TYPE`, or the value errors of the tag.
32
+ */
33
+ array(values: readonly unknown[], elementType: string): SqlFragment;
34
+ /**
35
+ * A cast of an expression: `sql.cast(expr, 'numeric')` → `(expr)::numeric`. The type name is
36
+ * validated like `sql.param` casts. @throws {SqlError} `SQL_INVALID_TYPE` or `SQL_NOT_A_FRAGMENT`.
37
+ */
38
+ cast(value: SqlFragment, type: string): SqlFragment;
39
+ /**
40
+ * Joins fragments with a separator (default `, `). Joining an empty list renders nothing.
41
+ * @throws {SqlError} `SQL_NOT_A_FRAGMENT` if an item is not a fragment.
42
+ */
43
+ join(fragments: readonly SqlFragment[], separator?: SqlFragment): SqlFragment;
44
+ /** A fragment that renders nothing. */
45
+ readonly empty: SqlFragment;
46
+ }
47
+ export declare const sql: SqlTag;
@@ -0,0 +1,123 @@
1
+ import { fragment, isSql } from './ast.js';
2
+ import { SqlError } from './errors.js';
3
+ /** PostgreSQL keeps the first 63 bytes of an identifier (NAMEDATALEN - 1). */
4
+ const MAX_IDENTIFIER_LENGTH = 63;
5
+ /** Lower-case snake_case, matching Shutro's naming (RFC 0001 §7.5). */
6
+ const IDENTIFIER = /^[a-z_][a-z0-9_]*$/;
7
+ /** Type names such as `numeric`, `numeric(20, 6)`, `timestamp with time zone`. Arrays only through `sql.array`. */
8
+ const TYPE_NAME = /^[a-z_][a-z0-9_]*( [a-z_][a-z0-9_]*)*(\(\d+(, ?\d+)?\))?$/;
9
+ function checkValue(value) {
10
+ if (value === undefined) {
11
+ throw new SqlError('SQL_UNDEFINED_PARAM', 'A SQL parameter is undefined.', 'Pass null for SQL NULL; undefined usually means a missing property or variable.');
12
+ }
13
+ if (typeof value === 'number' && !Number.isFinite(value)) {
14
+ throw new SqlError('SQL_INVALID_NUMBER', `A SQL parameter is ${value}.`, 'Only finite numbers can be sent. Check the calculation, or pass null.');
15
+ }
16
+ if (typeof value === 'function' || typeof value === 'symbol') {
17
+ throw new SqlError('SQL_INVALID_PARAM', `A SQL parameter is a ${typeof value}.`, 'Interpolate a value (string, number, bigint, boolean, null, Date, Uint8Array, array) or a sql fragment.');
18
+ }
19
+ if (Array.isArray(value))
20
+ for (const item of value)
21
+ checkValue(item);
22
+ }
23
+ function param(value, cast) {
24
+ checkValue(value);
25
+ return Object.freeze({ kind: 'param', value, cast });
26
+ }
27
+ function checkType(type) {
28
+ if (type.length > 64 || !TYPE_NAME.test(type)) {
29
+ throw new SqlError('SQL_INVALID_TYPE', `${JSON.stringify(type)} is not a valid PostgreSQL type name for a cast.`, 'Use a plain type such as numeric, numeric(20, 6), bigint or timestamp with time zone; use sql.array() for arrays.');
30
+ }
31
+ return type;
32
+ }
33
+ function isTemplate(strings, values) {
34
+ return (Array.isArray(strings) &&
35
+ Object.isFrozen(strings) &&
36
+ Array.isArray(strings.raw) &&
37
+ strings.length === values.length + 1 &&
38
+ strings.every((s) => typeof s === 'string'));
39
+ }
40
+ function tag(strings, ...values) {
41
+ if (!isTemplate(strings, values)) {
42
+ throw new SqlError('SQL_NOT_A_TEMPLATE', 'sql was called with something other than a template literal.', 'Write sql`...` with the SQL in the template; put runtime values in template placeholders so they become parameters.');
43
+ }
44
+ const nodes = [];
45
+ strings.forEach((text, i) => {
46
+ if (text !== '')
47
+ nodes.push(Object.freeze({ kind: 'text', text }));
48
+ if (i < values.length) {
49
+ const value = values[i];
50
+ nodes.push(isSql(value) ? value.node : param(value, undefined));
51
+ }
52
+ });
53
+ return fragment({ kind: 'seq', nodes: Object.freeze(nodes) });
54
+ }
55
+ const COMMA = tag `, `;
56
+ export const sql = Object.assign(tag, {
57
+ id(...parts) {
58
+ if (parts.length === 0) {
59
+ throw new SqlError('SQL_INVALID_IDENTIFIER', 'sql.id() was called without a name.', 'Pass at least one identifier part.');
60
+ }
61
+ for (const part of parts) {
62
+ if (typeof part !== 'string' ||
63
+ part.length > MAX_IDENTIFIER_LENGTH ||
64
+ !IDENTIFIER.test(part)) {
65
+ throw new SqlError('SQL_INVALID_IDENTIFIER', `${JSON.stringify(part)} is not a valid identifier.`, `Use lower-case snake_case (a-z, 0-9, _), starting with a letter or _, at most ${MAX_IDENTIFIER_LENGTH} characters. Identifiers must come from the registry, never from user input.`);
66
+ }
67
+ }
68
+ return fragment({ kind: 'ident', parts: Object.freeze([...parts]) });
69
+ },
70
+ param(value, type) {
71
+ return fragment(param(value, checkType(type)));
72
+ },
73
+ array(values, elementType) {
74
+ if (!Array.isArray(values)) {
75
+ throw new SqlError('SQL_INVALID_PARAM', `sql.array() expects an array, got ${typeof values}.`, 'Pass an array of values; use sql.param() for a single value.');
76
+ }
77
+ const type = checkType(elementType);
78
+ // Arrays of bytes: the driver infers `bytea` from the elements and the `bytea[]` cast then fails. They travel
79
+ // as hex text (`\x…`) and are cast element-wise on the server.
80
+ if (type === 'bytea') {
81
+ const hex = values.map((v) => v instanceof Uint8Array ? `\\x${Buffer.from(v).toString('hex')}` : v);
82
+ return fragment({
83
+ kind: 'seq',
84
+ nodes: Object.freeze([
85
+ Object.freeze({ kind: 'text', text: '(' }),
86
+ param(hex, 'text[]'),
87
+ Object.freeze({ kind: 'text', text: ')::bytea[]' }),
88
+ ]),
89
+ });
90
+ }
91
+ return fragment(param(values, `${type}[]`));
92
+ },
93
+ cast(value, type) {
94
+ if (!isSql(value)) {
95
+ throw new SqlError('SQL_NOT_A_FRAGMENT', 'sql.cast() expects a sql fragment.', 'Pass an expression built with the sql tag; cast bound values with sql.param(value, type).');
96
+ }
97
+ const target = checkType(type);
98
+ return fragment({
99
+ kind: 'seq',
100
+ nodes: Object.freeze([
101
+ Object.freeze({ kind: 'text', text: '(' }),
102
+ value.node,
103
+ Object.freeze({ kind: 'text', text: `)::${target}` }),
104
+ ]),
105
+ });
106
+ },
107
+ join(fragments, separator = COMMA) {
108
+ if (!isSql(separator)) {
109
+ throw new SqlError('SQL_NOT_A_FRAGMENT', 'The sql.join() separator is not a sql fragment.', 'Pass the separator as sql`...`, e.g. sql` AND `.');
110
+ }
111
+ const nodes = [];
112
+ fragments.forEach((f, i) => {
113
+ if (!isSql(f)) {
114
+ throw new SqlError('SQL_NOT_A_FRAGMENT', `sql.join() item ${i} is not a sql fragment.`, 'Wrap each item with sql`...` (values inside become parameters).');
115
+ }
116
+ if (i > 0)
117
+ nodes.push(separator.node);
118
+ nodes.push(f.node);
119
+ });
120
+ return fragment({ kind: 'seq', nodes: Object.freeze(nodes) });
121
+ },
122
+ empty: fragment({ kind: 'seq', nodes: Object.freeze([]) }),
123
+ });
package/package.json CHANGED
@@ -1,6 +1,84 @@
1
1
  {
2
2
  "name": "shutro",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "The ORM built for business software: type-safe, secure-by-default, multi-company, audit-ready PostgreSQL ORM for Node.js and TypeScript.",
5
+ "keywords": [
6
+ "orm",
7
+ "postgresql",
8
+ "postgres",
9
+ "typescript",
10
+ "erp",
11
+ "accounting",
12
+ "multi-company",
13
+ "audit",
14
+ "rls"
15
+ ],
16
+ "author": {
17
+ "name": "Isahaq",
18
+ "email": "hmisahaq01@gmail.com"
19
+ },
20
+ "license": "MIT",
21
+ "homepage": "https://github.com/isahaq1/shutro#readme",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/isahaq1/shutro.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/isahaq1/shutro/issues"
28
+ },
29
+ "type": "module",
30
+ "sideEffects": false,
31
+ "engines": {
32
+ "node": ">=24"
33
+ },
34
+ "bin": {
35
+ "shutro": "./dist/cli/bin.js"
36
+ },
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/core/index.d.ts",
40
+ "default": "./dist/core/index.js"
41
+ },
42
+ "./sql": {
43
+ "types": "./dist/sql/index.d.ts",
44
+ "default": "./dist/sql/index.js"
45
+ },
46
+ "./driver-pg": {
47
+ "types": "./dist/driver-pg/index.d.ts",
48
+ "default": "./dist/driver-pg/index.js"
49
+ },
50
+ "./migrate": {
51
+ "types": "./dist/migrate/index.d.ts",
52
+ "default": "./dist/migrate/index.js"
53
+ },
54
+ "./cli": {
55
+ "types": "./dist/cli/index.d.ts",
56
+ "default": "./dist/cli/index.js"
57
+ },
58
+ "./security": {
59
+ "types": "./dist/security/index.d.ts",
60
+ "default": "./dist/security/index.js"
61
+ },
62
+ "./audit": {
63
+ "types": "./dist/audit/index.d.ts",
64
+ "default": "./dist/audit/index.js"
65
+ },
66
+ "./sequence": {
67
+ "types": "./dist/sequence/index.d.ts",
68
+ "default": "./dist/sequence/index.js"
69
+ },
70
+ "./i18n": {
71
+ "types": "./dist/i18n/index.d.ts",
72
+ "default": "./dist/i18n/index.js"
73
+ }
74
+ },
75
+ "files": [
76
+ "dist",
77
+ "README.md",
78
+ "LICENSE"
79
+ ],
80
+ "dependencies": {
81
+ "decimal.js": "^10.6.0",
82
+ "postgres": "^3.4.9"
83
+ }
84
+ }