@rawsql-ts/sql-contract 0.3.1 → 0.3.2

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.
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writerPresets = void 0;
4
+ const sanitizeColumn = (column) => column
5
+ .replace(/[^A-Za-z0-9_]/g, '_')
6
+ .replace(/__+/g, '_')
7
+ .replace(/^_+|_+$/g, '') || 'param';
8
+ const createNumberedBinder = (format) => {
9
+ let index = 0;
10
+ const params = [];
11
+ return {
12
+ params,
13
+ bind(value, _column) {
14
+ index += 1;
15
+ params.push(value);
16
+ return format(index);
17
+ },
18
+ };
19
+ };
20
+ exports.writerPresets = {
21
+ indexed() {
22
+ return {
23
+ placeholderStyle: 'indexed',
24
+ paramsShape: 'array',
25
+ createBinder: () => createNumberedBinder((index) => `$${index}`),
26
+ };
27
+ },
28
+ anonymous() {
29
+ return {
30
+ placeholderStyle: 'question',
31
+ paramsShape: 'array',
32
+ createBinder: () => {
33
+ const params = [];
34
+ return {
35
+ params,
36
+ bind(value) {
37
+ params.push(value);
38
+ return '?';
39
+ },
40
+ };
41
+ },
42
+ };
43
+ },
44
+ named(options) {
45
+ var _a;
46
+ const formatPlaceholder = (_a = options === null || options === void 0 ? void 0 : options.formatPlaceholder) !== null && _a !== void 0 ? _a : ((paramName) => paramName);
47
+ return {
48
+ placeholderStyle: 'named',
49
+ paramsShape: 'object',
50
+ createBinder: () => {
51
+ let counter = 0;
52
+ const params = {};
53
+ return {
54
+ params,
55
+ bind(value, column) {
56
+ counter += 1;
57
+ const sanitized = sanitizeColumn(column);
58
+ const paramName = `${sanitized}_${counter}`;
59
+ params[paramName] = value;
60
+ return formatPlaceholder(paramName);
61
+ },
62
+ };
63
+ },
64
+ };
65
+ },
66
+ };
67
+ //# sourceMappingURL=presets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.js","sourceRoot":"","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AE,iBAAiB,mCAAI,CAAC,CAAC,SAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,CAAA;QAE1F,OAAO;YACL,gBAAgB,EAAE,OAAO;YACzB,WAAW,EAAE,QAAQ;YACrB,YAAY,EAAE,GAAG,EAAE;gBACjB,IAAI,OAAO,GAAG,CAAC,CAAA;gBACf,MAAM,MAAM,GAA+B,EAAE,CAAA;gBAC7C,OAAO;oBACL,MAAM;oBACN,IAAI,CAAC,KAAiB,EAAE,MAAc;wBACpC,OAAO,IAAI,CAAC,CAAA;wBACZ,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAA;wBACxC,MAAM,SAAS,GAAG,GAAG,SAAS,IAAI,OAAO,EAAE,CAAA;wBAC3C,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,CAAA;wBACzB,OAAO,iBAAiB,CAAC,SAAS,CAAC,CAAA;oBACrC,CAAC;iBACF,CAAA;YACH,CAAC;SACF,CAAA;IACH,CAAC;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rawsql-ts/sql-contract",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Lightweight mapper and writer helpers that keep client SQL authoritative while exposing an explicit contract for data hydration and CUD emitters.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,14 +34,6 @@
34
34
  "default": "./dist/writer/*.js"
35
35
  }
36
36
  },
37
- "scripts": {
38
- "build": "tsc -p tsconfig.json",
39
- "test": "vitest run --config vitest.config.ts",
40
- "test:consumer-validation": "vitest run --config vitest.config.ts",
41
- "test:integration": "vitest run --config ../../vitest.integration.config.ts",
42
- "test:watch": "vitest --config vitest.config.ts",
43
- "lint": "eslint src --ext .ts"
44
- },
45
37
  "keywords": [
46
38
  "sql",
47
39
  "mapper",
@@ -70,5 +62,13 @@
70
62
  },
71
63
  "files": [
72
64
  "dist"
73
- ]
74
- }
65
+ ],
66
+ "scripts": {
67
+ "build": "tsc -p tsconfig.json",
68
+ "test": "vitest run --config vitest.config.ts",
69
+ "test:consumer-validation": "vitest run --config vitest.config.ts",
70
+ "test:integration": "vitest run --config ../../vitest.integration.config.ts",
71
+ "test:watch": "vitest --config vitest.config.ts",
72
+ "lint": "eslint src --ext .ts"
73
+ }
74
+ }