@centrali-io/centrali-sdk 5.3.0 → 5.5.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.
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ // ---------------------------------------------------------------------------
3
+ // AUTO-GENERATED — DO NOT EDIT BY HAND.
4
+ //
5
+ // Source: services/backend/shared/query/src/types.ts (@centrali/query)
6
+ // Regenerate: `npm run sync:query-types` (also runs on prebuild).
7
+ //
8
+ // The shared package is the single source of truth for canonical query types.
9
+ // This file is a types-only port so the published SDK stays a single npm
10
+ // install. See CEN-1194 for the alignment, CEN-1202 for runtime bundling.
11
+ // ---------------------------------------------------------------------------
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.RECORDS_PAGE_MAX_LIMIT = exports.RECORDS_PAGE_DEFAULT_LIMIT = exports.OPERATOR_METADATA = exports.CANONICAL_OPERATORS = void 0;
14
+ exports.operatorsForFieldType = operatorsForFieldType;
15
+ exports.CANONICAL_OPERATORS = [
16
+ 'eq',
17
+ 'ne',
18
+ 'gt',
19
+ 'gte',
20
+ 'lt',
21
+ 'lte',
22
+ 'in',
23
+ 'nin',
24
+ 'contains',
25
+ 'startsWith',
26
+ 'endsWith',
27
+ 'hasAny',
28
+ 'hasAll',
29
+ 'exists',
30
+ ];
31
+ exports.OPERATOR_METADATA = {
32
+ eq: {
33
+ operator: 'eq',
34
+ label: 'equals',
35
+ shortLabel: '=',
36
+ valueShape: 'scalar',
37
+ applicableTypes: ['any'],
38
+ },
39
+ ne: {
40
+ operator: 'ne',
41
+ label: 'not equals',
42
+ shortLabel: '≠',
43
+ valueShape: 'scalar',
44
+ applicableTypes: ['any'],
45
+ },
46
+ gt: {
47
+ operator: 'gt',
48
+ label: 'greater than',
49
+ shortLabel: '>',
50
+ valueShape: 'scalar',
51
+ applicableTypes: ['number', 'datetime'],
52
+ },
53
+ gte: {
54
+ operator: 'gte',
55
+ label: 'greater or equal',
56
+ shortLabel: '≥',
57
+ valueShape: 'scalar',
58
+ applicableTypes: ['number', 'datetime'],
59
+ },
60
+ lt: {
61
+ operator: 'lt',
62
+ label: 'less than',
63
+ shortLabel: '<',
64
+ valueShape: 'scalar',
65
+ applicableTypes: ['number', 'datetime'],
66
+ },
67
+ lte: {
68
+ operator: 'lte',
69
+ label: 'less or equal',
70
+ shortLabel: '≤',
71
+ valueShape: 'scalar',
72
+ applicableTypes: ['number', 'datetime'],
73
+ },
74
+ in: {
75
+ operator: 'in',
76
+ label: 'in',
77
+ valueShape: 'array',
78
+ applicableTypes: ['string', 'number', 'datetime'],
79
+ },
80
+ nin: {
81
+ operator: 'nin',
82
+ label: 'not in',
83
+ valueShape: 'array',
84
+ applicableTypes: ['string', 'number', 'datetime'],
85
+ },
86
+ contains: {
87
+ operator: 'contains',
88
+ label: 'contains',
89
+ valueShape: 'scalar',
90
+ applicableTypes: ['string'],
91
+ },
92
+ startsWith: {
93
+ operator: 'startsWith',
94
+ label: 'starts with',
95
+ valueShape: 'scalar',
96
+ applicableTypes: ['string'],
97
+ },
98
+ endsWith: {
99
+ operator: 'endsWith',
100
+ label: 'ends with',
101
+ valueShape: 'scalar',
102
+ applicableTypes: ['string'],
103
+ },
104
+ hasAny: {
105
+ operator: 'hasAny',
106
+ label: 'has any of',
107
+ valueShape: 'array',
108
+ applicableTypes: ['array'],
109
+ },
110
+ hasAll: {
111
+ operator: 'hasAll',
112
+ label: 'has all of',
113
+ valueShape: 'array',
114
+ applicableTypes: ['array'],
115
+ },
116
+ exists: {
117
+ operator: 'exists',
118
+ label: 'exists',
119
+ valueShape: 'boolean',
120
+ applicableTypes: ['any'],
121
+ },
122
+ };
123
+ /**
124
+ * Operators applicable to a given field-type. Used by builder UIs to narrow
125
+ * the dropdown when the user selects a field; falls back to `any`-applicable
126
+ * operators when the type is unknown.
127
+ */
128
+ function operatorsForFieldType(type) {
129
+ const t = type;
130
+ return exports.CANONICAL_OPERATORS.map((op) => exports.OPERATOR_METADATA[op]).filter((meta) => meta.applicableTypes.includes('any') || meta.applicableTypes.includes(t));
131
+ }
132
+ /**
133
+ * Records Phase 1 page defaults (contract §6).
134
+ * Same default and cap for GET adapter and POST query body.
135
+ */
136
+ exports.RECORDS_PAGE_DEFAULT_LIMIT = 50;
137
+ exports.RECORDS_PAGE_MAX_LIMIT = 500;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Type-only smoke for the canonical query surface added in 5.5.0 (CEN-1194).
3
+ *
4
+ * Runs as part of `npm run build` because it lives in the same project as
5
+ * `index.ts`. Compiling means the canonical types and new methods type-check
6
+ * end-to-end. There is no runtime assertion — when the SDK has a real test
7
+ * harness (separate ticket), these calls will turn into integration tests.
8
+ *
9
+ * To run manually:
10
+ * npx tsc --noEmit scripts/smoke-types.ts
11
+ */
12
+ export {};
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * Type-only smoke for the canonical query surface added in 5.5.0 (CEN-1194).
4
+ *
5
+ * Runs as part of `npm run build` because it lives in the same project as
6
+ * `index.ts`. Compiling means the canonical types and new methods type-check
7
+ * end-to-end. There is no runtime assertion — when the SDK has a real test
8
+ * harness (separate ticket), these calls will turn into integration tests.
9
+ *
10
+ * To run manually:
11
+ * npx tsc --noEmit scripts/smoke-types.ts
12
+ */
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ const index_1 = require("../index");
24
+ // ---- Canonical type ergonomics ----
25
+ const _operators = index_1.CANONICAL_OPERATORS;
26
+ const _defaultLimit = index_1.RECORDS_PAGE_DEFAULT_LIMIT;
27
+ const _maxLimit = index_1.RECORDS_PAGE_MAX_LIMIT;
28
+ const _eqOnly = { eq: 'paid' };
29
+ // Uncommenting the next line MUST fail to compile (exactly-one-operator rule):
30
+ // const _twoOps: FieldCondition = { eq: 'paid', ne: 'cancelled' };
31
+ const _where = {
32
+ and: [
33
+ { 'data.status': { eq: 'open' } },
34
+ { or: [
35
+ { 'data.amount': { gte: 100 } },
36
+ { 'data.priority': { eq: 'high' } }
37
+ ] },
38
+ { not: { 'data.archived': { eq: true } } }
39
+ ]
40
+ };
41
+ const _sort = [
42
+ { field: 'createdAt', direction: 'desc' },
43
+ { field: 'data.amount', direction: 'asc' }
44
+ ];
45
+ const _pageOffset = { limit: 50, offset: 100 };
46
+ const _pageCursor = { limit: 50, cursor: 'abc' };
47
+ // Uncommenting must fail (offset and cursor are mutually exclusive):
48
+ // const _pageBoth: PageClause = { limit: 50, offset: 0, cursor: 'abc' };
49
+ const _select = { fields: ['id', 'data.status', 'data.customer'] };
50
+ const _def = {
51
+ resource: 'orders',
52
+ where: _where,
53
+ sort: _sort,
54
+ page: _pageOffset,
55
+ select: _select,
56
+ };
57
+ function exerciseSdk() {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const client = new index_1.CentraliSDK({
60
+ baseUrl: 'http://localhost',
61
+ workspaceId: 'demo',
62
+ token: 'test',
63
+ });
64
+ // RecordsManager.query → QueryResult<T>
65
+ const r1 = yield client.records.query('orders', _def);
66
+ console.log(r1.data.length, r1.meta.limit);
67
+ // Resource backfill — caller can omit `resource` and we fill it from arg1
68
+ yield client.records.query('orders', { where: _where });
69
+ // RecordsManager.test → QueryResult<T>
70
+ yield client.records.test('orders', { resource: 'orders' });
71
+ // RecordsManager.list → ApiResponse<T[]> (legacy GET adapter envelope kept)
72
+ const r2 = yield client.records.list('orders', {
73
+ 'data.status': 'paid',
74
+ sort: '-createdAt',
75
+ });
76
+ console.log(r2.data.length);
77
+ // RecordsManager.search — text sugar, returns QueryResult<T>
78
+ const r3 = yield client.records.search('orders', 'urgent shipping', {
79
+ page: { limit: 25 },
80
+ });
81
+ console.log(r3.data, r3.meta.mode);
82
+ // (Saved-query SDK surface — `client.savedQueries` — is deliberately not
83
+ // shipped in 5.5.0. The /saved-queries/* HTTP routes are Phase 4 work
84
+ // tracked in CEN-1198; the canonical SDK manager lands alongside them.
85
+ // Today's `client.smartQueries` namespace is the supported way to call
86
+ // saved queries from the SDK.)
87
+ // Top-level canonical overload
88
+ const r4 = yield client.queryRecords('orders', {
89
+ resource: 'orders',
90
+ where: { 'data.status': { eq: 'paid' } },
91
+ page: { limit: 100 },
92
+ });
93
+ console.log(r4.data, r4.meta);
94
+ // Legacy GET-adapter form still type-checks (and emits a one-shot warn at runtime)
95
+ const r5 = yield client.queryRecords('orders', {
96
+ 'data.status': 'paid',
97
+ sort: '-createdAt',
98
+ });
99
+ console.log(r5.data);
100
+ });
101
+ }
102
+ void exerciseSdk;