@kozou/ui-core 1.7.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.
- package/LICENSE +202 -0
- package/README.md +40 -0
- package/dist/adapter/errors.d.ts +16 -0
- package/dist/adapter/errors.d.ts.map +1 -0
- package/dist/adapter/errors.js +19 -0
- package/dist/adapter/errors.js.map +1 -0
- package/dist/adapter/index.d.ts +8 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +15 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/adapter/kozou-api.d.ts +35 -0
- package/dist/adapter/kozou-api.d.ts.map +1 -0
- package/dist/adapter/kozou-api.js +215 -0
- package/dist/adapter/kozou-api.js.map +1 -0
- package/dist/adapter/postgrest.d.ts +51 -0
- package/dist/adapter/postgrest.d.ts.map +1 -0
- package/dist/adapter/postgrest.js +343 -0
- package/dist/adapter/postgrest.js.map +1 -0
- package/dist/adapter/types.d.ts +6 -0
- package/dist/adapter/types.d.ts.map +1 -0
- package/dist/adapter/types.js +3 -0
- package/dist/adapter/types.js.map +1 -0
- package/dist/detail/format-cell.d.ts +7 -0
- package/dist/detail/format-cell.d.ts.map +1 -0
- package/dist/detail/format-cell.js +50 -0
- package/dist/detail/format-cell.js.map +1 -0
- package/dist/detail/resolve-fk-labels.d.ts +23 -0
- package/dist/detail/resolve-fk-labels.d.ts.map +1 -0
- package/dist/detail/resolve-fk-labels.js +118 -0
- package/dist/detail/resolve-fk-labels.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/list/list-href.d.ts +21 -0
- package/dist/list/list-href.d.ts.map +1 -0
- package/dist/list/list-href.js +50 -0
- package/dist/list/list-href.js.map +1 -0
- package/dist/query/list-params.d.ts +18 -0
- package/dist/query/list-params.d.ts.map +1 -0
- package/dist/query/list-params.js +55 -0
- package/dist/query/list-params.js.map +1 -0
- package/dist/resource-id.d.ts +24 -0
- package/dist/resource-id.d.ts.map +1 -0
- package/dist/resource-id.js +58 -0
- package/dist/resource-id.js.map +1 -0
- package/dist/server/fk-row-cache.d.ts +27 -0
- package/dist/server/fk-row-cache.d.ts.map +1 -0
- package/dist/server/fk-row-cache.js +54 -0
- package/dist/server/fk-row-cache.js.map +1 -0
- package/dist/server/schema-cache.d.ts +22 -0
- package/dist/server/schema-cache.d.ts.map +1 -0
- package/dist/server/schema-cache.js +46 -0
- package/dist/server/schema-cache.js.map +1 -0
- package/dist/view/columns.d.ts +4 -0
- package/dist/view/columns.d.ts.map +1 -0
- package/dist/view/columns.js +22 -0
- package/dist/view/columns.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# @kozou/ui-core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic UI logic for Kozou reference Admin UIs.
|
|
4
|
+
|
|
5
|
+
Kozou compiles a PostgreSQL schema (DDL + `COMMENT`) into a
|
|
6
|
+
`SchemaContext` and talks to a backend through the `DataAdapter`
|
|
7
|
+
interface (both defined in [`@kozou/core`](https://www.npmjs.com/package/@kozou/core)).
|
|
8
|
+
This package holds the **read-path** logic that turns those two inputs
|
|
9
|
+
into the data a list/detail view renders, with **no Svelte, SvelteKit,
|
|
10
|
+
React, or any UI-framework runtime dependency**.
|
|
11
|
+
|
|
12
|
+
It exists so more than one UI can share the exact same behaviour instead
|
|
13
|
+
of re-implementing (and re-acquiring the bugs of) list parsing, FK label
|
|
14
|
+
resolution, composite-key handling, and so on. The reference
|
|
15
|
+
[`@kozou/svelte-ui`](https://www.npmjs.com/package/@kozou/svelte-ui)
|
|
16
|
+
consumes it; a renderer in another framework can consume the same logic.
|
|
17
|
+
|
|
18
|
+
## What's here
|
|
19
|
+
|
|
20
|
+
- **DataAdapter implementations** — two pure HTTP clients (the in-house
|
|
21
|
+
`@kozou/api` adapter and the external-REST adapter). They do no DB
|
|
22
|
+
introspection; they speak a wire format.
|
|
23
|
+
- **List params** — URL ⇄ `ListParams` (pagination, sort, filter, search).
|
|
24
|
+
- **List href helpers** — build sort/pagination links and format list cells.
|
|
25
|
+
- **View columns** — display/search column heuristics for a `ViewContext`.
|
|
26
|
+
- **Detail** — cell formatting and foreign-key label resolution
|
|
27
|
+
(loader-injected, so it is pure and testable).
|
|
28
|
+
- **Resource id** — composite-key segment encode / decode / parse.
|
|
29
|
+
- **Caches** — TTL + dedup caches for the `SchemaContext` and FK target
|
|
30
|
+
rows (clock- and loader-injected; no Node-only dependency).
|
|
31
|
+
|
|
32
|
+
## Stability
|
|
33
|
+
|
|
34
|
+
The surface here tracks the reference Admin UI it was extracted from.
|
|
35
|
+
It is published so reference UIs can depend on it; it is not yet a
|
|
36
|
+
documented public contract for third-party UIs.
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
Apache-2.0.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type AdapterErrorCode = 'http' | 'network' | 'parse' | 'config';
|
|
2
|
+
export interface AdapterErrorInit {
|
|
3
|
+
readonly message: string;
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly url: string;
|
|
6
|
+
readonly responseBody: string | null;
|
|
7
|
+
readonly code: AdapterErrorCode;
|
|
8
|
+
}
|
|
9
|
+
export declare class AdapterError extends Error {
|
|
10
|
+
readonly status: number;
|
|
11
|
+
readonly url: string;
|
|
12
|
+
readonly responseBody: string | null;
|
|
13
|
+
readonly code: AdapterErrorCode;
|
|
14
|
+
constructor(init: AdapterErrorInit);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/adapter/errors.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEvE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACjC;AAED,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;gBAEpB,IAAI,EAAE,gBAAgB;CAQnC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Common error base for DataAdapter implementations.
|
|
2
|
+
// Concrete adapters (see ./index.ts) extend AdapterError with their
|
|
3
|
+
// own subclass so callers can catch by family without coupling to a
|
|
4
|
+
// specific backend.
|
|
5
|
+
export class AdapterError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
url;
|
|
8
|
+
responseBody;
|
|
9
|
+
code;
|
|
10
|
+
constructor(init) {
|
|
11
|
+
super(init.message);
|
|
12
|
+
this.name = 'AdapterError';
|
|
13
|
+
this.status = init.status;
|
|
14
|
+
this.url = init.url;
|
|
15
|
+
this.responseBody = init.responseBody;
|
|
16
|
+
this.code = init.code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/adapter/errors.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,oEAAoE;AACpE,oEAAoE;AACpE,oBAAoB;AAYpB,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,MAAM,CAAS;IACf,GAAG,CAAS;IACZ,YAAY,CAAgB;IAC5B,IAAI,CAAmB;IAEhC,YAAY,IAAsB;QAChC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { FetchLike } from './types.js';
|
|
2
|
+
export type { AdapterErrorCode, AdapterErrorInit } from './errors.js';
|
|
3
|
+
export { AdapterError } from './errors.js';
|
|
4
|
+
export type { PostgrestAdapterOptions, PostgrestPrimaryKeyResolver, } from './postgrest.js';
|
|
5
|
+
export { PostgrestAdapterError, PostgrestDataAdapter } from './postgrest.js';
|
|
6
|
+
export type { KozouApiAdapterOptions } from './kozou-api.js';
|
|
7
|
+
export { KozouApiAdapterError, KozouApiDataAdapter } from './kozou-api.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAYA,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EACV,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,YAAY,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// DataAdapter implementations and their shared surface.
|
|
2
|
+
//
|
|
3
|
+
// Concrete adapter implementations land in sibling modules:
|
|
4
|
+
// - ./postgrest.ts -> PostgrestDataAdapter (external REST adapter)
|
|
5
|
+
// - ./kozou-api.ts -> KozouApiDataAdapter (in-house @kozou/api)
|
|
6
|
+
//
|
|
7
|
+
// The PostgrestDataAdapter is the only adapter expected to mention the
|
|
8
|
+
// external REST server by name; the license-check workflow whitelists
|
|
9
|
+
// the files that carry that identifier (postgrest.ts, this index
|
|
10
|
+
// re-export, and the package barrel src/index.ts). The
|
|
11
|
+
// KozouApiDataAdapter speaks the in-house @kozou/api wire format.
|
|
12
|
+
export { AdapterError } from './errors.js';
|
|
13
|
+
export { PostgrestAdapterError, PostgrestDataAdapter } from './postgrest.js';
|
|
14
|
+
export { KozouApiAdapterError, KozouApiDataAdapter } from './kozou-api.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,4DAA4D;AAC5D,sEAAsE;AACtE,mEAAmE;AACnE,EAAE;AACF,uEAAuE;AACvE,sEAAsE;AACtE,iEAAiE;AACjE,uDAAuD;AACvD,kEAAkE;AAIlE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DataAdapter, ListParams, ListResult, RelationOption, ResourceId, SearchRelationParams } from '@kozou/core';
|
|
2
|
+
import { AdapterError, type AdapterErrorInit } from './errors.js';
|
|
3
|
+
import type { FetchLike } from './types.js';
|
|
4
|
+
export interface KozouApiAdapterOptions {
|
|
5
|
+
/** Base URL of the @kozou/api server (trailing slash is stripped). */
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
/** Static headers merged into every request (e.g. Authorization). */
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
/** Fetch override; defaults to `globalThis.fetch`. Injection point for tests. */
|
|
10
|
+
fetch?: FetchLike;
|
|
11
|
+
/** Page size used when ListParams.pageSize is omitted. */
|
|
12
|
+
defaultPageSize?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare class KozouApiAdapterError extends AdapterError {
|
|
15
|
+
constructor(init: AdapterErrorInit);
|
|
16
|
+
}
|
|
17
|
+
export declare class KozouApiDataAdapter implements DataAdapter {
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly staticHeaders;
|
|
20
|
+
private readonly fetchImpl;
|
|
21
|
+
private readonly defaultPageSize;
|
|
22
|
+
constructor(opts: KozouApiAdapterOptions);
|
|
23
|
+
list(resource: string, params: ListParams): Promise<ListResult>;
|
|
24
|
+
get(resource: string, id: ResourceId): Promise<Record<string, unknown>>;
|
|
25
|
+
create(resource: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
26
|
+
update(resource: string, id: ResourceId, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
27
|
+
delete(resource: string, id: ResourceId): Promise<void>;
|
|
28
|
+
searchRelation(resource: string, params: SearchRelationParams): Promise<RelationOption[]>;
|
|
29
|
+
callFunction(qualifiedName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
30
|
+
private itemUrl;
|
|
31
|
+
private getJson;
|
|
32
|
+
private sendJson;
|
|
33
|
+
private send;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=kozou-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kozou-api.d.ts","sourceRoot":"","sources":["../../src/adapter/kozou-api.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAU5C,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,iFAAiF;IACjF,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,0DAA0D;IAC1D,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,oBAAqB,SAAQ,YAAY;gBACxC,IAAI,EAAE,gBAAgB;CAInC;AAED,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;gBAE7B,IAAI,EAAE,sBAAsB;IAiBlC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAuB/D,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAKvE,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAK7B,MAAM,CACV,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,UAAU,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAO7B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAOvD,cAAc,CAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC;IAetB,YAAY,CAChB,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,OAAO,CAAC;IAoBnB,OAAO,CAAC,OAAO;YAOD,OAAO;YAOP,QAAQ;YAeR,IAAI;CAkBnB"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// KozouApiDataAdapter — DataAdapter implementation that speaks the
|
|
2
|
+
// in-house @kozou/api REST wire format. It is a
|
|
3
|
+
// sibling of the other adapter in this directory; getAdapter() selects it
|
|
4
|
+
// when the operator opts into the in-house API layer
|
|
5
|
+
// (KOZOU_ADAPTER_KIND=api). Like its sibling it ships no server code, only
|
|
6
|
+
// an HTTP client for the API surface.
|
|
7
|
+
//
|
|
8
|
+
// Wire format (see @kozou/api):
|
|
9
|
+
// GET /<resource>?page=&pageSize=&sort=f.asc,g.desc&search=&<col>=<v>
|
|
10
|
+
// GET /<resource>/<id>
|
|
11
|
+
// POST /<resource> (JSON body)
|
|
12
|
+
// PATCH /<resource>/<id> (JSON body)
|
|
13
|
+
// DELETE /<resource>/<id>
|
|
14
|
+
// GET /<resource>?as=options&label=&fields=&q=&limit=
|
|
15
|
+
import { AdapterError } from './errors.js';
|
|
16
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
17
|
+
const DEFAULT_RELATION_LIMIT = 20;
|
|
18
|
+
// The UI encodes free-text search as a `filters.__or` sentinel for the
|
|
19
|
+
// other adapter; the in-house API does free-text search through its own
|
|
20
|
+
// `search=` parameter, so this key is dropped from column filters here.
|
|
21
|
+
const OR_FILTER_KEY = '__or';
|
|
22
|
+
export class KozouApiAdapterError extends AdapterError {
|
|
23
|
+
constructor(init) {
|
|
24
|
+
super(init);
|
|
25
|
+
this.name = 'KozouApiAdapterError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export class KozouApiDataAdapter {
|
|
29
|
+
baseUrl;
|
|
30
|
+
staticHeaders;
|
|
31
|
+
fetchImpl;
|
|
32
|
+
defaultPageSize;
|
|
33
|
+
constructor(opts) {
|
|
34
|
+
if (typeof opts.baseUrl !== 'string' || opts.baseUrl.length === 0) {
|
|
35
|
+
throw configError('KozouApiDataAdapter: `baseUrl` is required.');
|
|
36
|
+
}
|
|
37
|
+
this.baseUrl = stripTrailingSlash(opts.baseUrl);
|
|
38
|
+
this.staticHeaders = { ...(opts.headers ?? {}) };
|
|
39
|
+
this.defaultPageSize = opts.defaultPageSize ?? DEFAULT_PAGE_SIZE;
|
|
40
|
+
const resolvedFetch = opts.fetch ?? globalThis.fetch;
|
|
41
|
+
if (typeof resolvedFetch !== 'function') {
|
|
42
|
+
throw configError('KozouApiDataAdapter: a `fetch` implementation is required (none injected, none on globalThis).');
|
|
43
|
+
}
|
|
44
|
+
this.fetchImpl = resolvedFetch;
|
|
45
|
+
}
|
|
46
|
+
async list(resource, params) {
|
|
47
|
+
const page = params.page ?? 1;
|
|
48
|
+
const pageSize = params.pageSize ?? this.defaultPageSize;
|
|
49
|
+
const query = new URLSearchParams();
|
|
50
|
+
query.set('page', String(page));
|
|
51
|
+
query.set('pageSize', String(pageSize));
|
|
52
|
+
appendSort(query, params.sort);
|
|
53
|
+
if (params.search !== undefined && params.search.length > 0) {
|
|
54
|
+
query.set('search', params.search);
|
|
55
|
+
}
|
|
56
|
+
appendFilters(query, params.filters);
|
|
57
|
+
const url = `${this.baseUrl}/${encodeResource(resource)}?${query.toString()}`;
|
|
58
|
+
const body = (await this.getJson(url));
|
|
59
|
+
return {
|
|
60
|
+
rows: Array.isArray(body.rows) ? body.rows : [],
|
|
61
|
+
total: typeof body.total === 'number' ? body.total : (body.rows?.length ?? 0),
|
|
62
|
+
page: typeof body.page === 'number' ? body.page : page,
|
|
63
|
+
pageSize: typeof body.pageSize === 'number' ? body.pageSize : pageSize,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async get(resource, id) {
|
|
67
|
+
const url = this.itemUrl(resource, id);
|
|
68
|
+
return (await this.getJson(url));
|
|
69
|
+
}
|
|
70
|
+
async create(resource, data) {
|
|
71
|
+
const url = `${this.baseUrl}/${encodeResource(resource)}`;
|
|
72
|
+
return (await this.sendJson('POST', url, data));
|
|
73
|
+
}
|
|
74
|
+
async update(resource, id, data) {
|
|
75
|
+
return (await this.sendJson('PATCH', this.itemUrl(resource, id), data));
|
|
76
|
+
}
|
|
77
|
+
async delete(resource, id) {
|
|
78
|
+
const url = this.itemUrl(resource, id);
|
|
79
|
+
const headers = { ...this.staticHeaders, Accept: 'application/json' };
|
|
80
|
+
const response = await this.send('DELETE', url, headers, undefined);
|
|
81
|
+
await assertOk(response, url);
|
|
82
|
+
}
|
|
83
|
+
async searchRelation(resource, params) {
|
|
84
|
+
const query = new URLSearchParams();
|
|
85
|
+
query.set('as', 'options');
|
|
86
|
+
query.set('label', params.labelField);
|
|
87
|
+
if (params.searchFields.length > 0) {
|
|
88
|
+
query.set('fields', params.searchFields.join(','));
|
|
89
|
+
}
|
|
90
|
+
if (params.query.length > 0)
|
|
91
|
+
query.set('q', params.query);
|
|
92
|
+
query.set('limit', String(params.limit ?? DEFAULT_RELATION_LIMIT));
|
|
93
|
+
const url = `${this.baseUrl}/${encodeResource(resource)}?${query.toString()}`;
|
|
94
|
+
const body = (await this.getJson(url));
|
|
95
|
+
return Array.isArray(body.options) ? body.options : [];
|
|
96
|
+
}
|
|
97
|
+
async callFunction(qualifiedName, args) {
|
|
98
|
+
// POST /rpc/<schema>.<fn> with the named-args body (issue #103). A 204
|
|
99
|
+
// (void return) yields null; otherwise the parsed JSON result (scalar /
|
|
100
|
+
// object / array) is returned verbatim.
|
|
101
|
+
const url = `${this.baseUrl}/rpc/${encodeURIComponent(qualifiedName)}`;
|
|
102
|
+
const headers = {
|
|
103
|
+
...this.staticHeaders,
|
|
104
|
+
Accept: 'application/json',
|
|
105
|
+
'Content-Type': 'application/json',
|
|
106
|
+
};
|
|
107
|
+
const response = await this.send('POST', url, headers, JSON.stringify(args));
|
|
108
|
+
await assertOk(response, url);
|
|
109
|
+
if (response.status === 204)
|
|
110
|
+
return null;
|
|
111
|
+
return readJson(response, url);
|
|
112
|
+
}
|
|
113
|
+
// Item path: `/<resource>/<id>`. A composite key encodes each component
|
|
114
|
+
// and joins them with an unescaped comma; the server decodes the segment,
|
|
115
|
+
// then splits on commas. A scalar
|
|
116
|
+
// key is encoded verbatim, so single-column keys are unchanged.
|
|
117
|
+
itemUrl(resource, id) {
|
|
118
|
+
const segment = Array.isArray(id)
|
|
119
|
+
? id.map((part) => encodeURIComponent(String(part))).join(',')
|
|
120
|
+
: encodeURIComponent(String(id));
|
|
121
|
+
return `${this.baseUrl}/${encodeResource(resource)}/${segment}`;
|
|
122
|
+
}
|
|
123
|
+
async getJson(url) {
|
|
124
|
+
const headers = { ...this.staticHeaders, Accept: 'application/json' };
|
|
125
|
+
const response = await this.send('GET', url, headers, undefined);
|
|
126
|
+
await assertOk(response, url);
|
|
127
|
+
return readJson(response, url);
|
|
128
|
+
}
|
|
129
|
+
async sendJson(method, url, data) {
|
|
130
|
+
const headers = {
|
|
131
|
+
...this.staticHeaders,
|
|
132
|
+
Accept: 'application/json',
|
|
133
|
+
'Content-Type': 'application/json',
|
|
134
|
+
};
|
|
135
|
+
const response = await this.send(method, url, headers, JSON.stringify(data));
|
|
136
|
+
await assertOk(response, url);
|
|
137
|
+
return readJson(response, url);
|
|
138
|
+
}
|
|
139
|
+
async send(method, url, headers, body) {
|
|
140
|
+
try {
|
|
141
|
+
return await this.fetchImpl(url, { method, headers, body });
|
|
142
|
+
}
|
|
143
|
+
catch (cause) {
|
|
144
|
+
throw new KozouApiAdapterError({
|
|
145
|
+
message: `KozouApiDataAdapter: ${method} ${url} failed before reaching the server: ${cause.message}`,
|
|
146
|
+
status: 0,
|
|
147
|
+
url,
|
|
148
|
+
responseBody: null,
|
|
149
|
+
code: 'network',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function stripTrailingSlash(url) {
|
|
155
|
+
return url.endsWith('/') ? url.slice(0, -1) : url;
|
|
156
|
+
}
|
|
157
|
+
function encodeResource(resource) {
|
|
158
|
+
return encodeURIComponent(resource);
|
|
159
|
+
}
|
|
160
|
+
function appendSort(query, sort) {
|
|
161
|
+
if (!sort || sort.length === 0)
|
|
162
|
+
return;
|
|
163
|
+
query.set('sort', sort.map((s) => `${s.field}.${s.order}`).join(','));
|
|
164
|
+
}
|
|
165
|
+
function appendFilters(query, filters) {
|
|
166
|
+
if (!filters)
|
|
167
|
+
return;
|
|
168
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
169
|
+
if (value === undefined || key === OR_FILTER_KEY)
|
|
170
|
+
continue;
|
|
171
|
+
query.set(key, String(value));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
async function readJson(response, url) {
|
|
175
|
+
try {
|
|
176
|
+
return await response.json();
|
|
177
|
+
}
|
|
178
|
+
catch (cause) {
|
|
179
|
+
throw new KozouApiAdapterError({
|
|
180
|
+
message: `KozouApiDataAdapter: failed to parse JSON response from ${url}: ${cause.message}`,
|
|
181
|
+
status: response.status,
|
|
182
|
+
url,
|
|
183
|
+
responseBody: null,
|
|
184
|
+
code: 'parse',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async function assertOk(response, url) {
|
|
189
|
+
if (response.ok)
|
|
190
|
+
return;
|
|
191
|
+
let body = null;
|
|
192
|
+
try {
|
|
193
|
+
body = await response.text();
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
body = null;
|
|
197
|
+
}
|
|
198
|
+
throw new KozouApiAdapterError({
|
|
199
|
+
message: `KozouApiDataAdapter: request to ${url} failed with status ${response.status}`,
|
|
200
|
+
status: response.status,
|
|
201
|
+
url,
|
|
202
|
+
responseBody: body,
|
|
203
|
+
code: 'http',
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function configError(message) {
|
|
207
|
+
return new KozouApiAdapterError({
|
|
208
|
+
message,
|
|
209
|
+
status: 0,
|
|
210
|
+
url: '',
|
|
211
|
+
responseBody: null,
|
|
212
|
+
code: 'config',
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=kozou-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kozou-api.js","sourceRoot":"","sources":["../../src/adapter/kozou-api.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,gDAAgD;AAChD,0EAA0E;AAC1E,qDAAqD;AACrD,2EAA2E;AAC3E,sCAAsC;AACtC,EAAE;AACF,gCAAgC;AAChC,2EAA2E;AAC3E,4BAA4B;AAC5B,mDAAmD;AACnD,mDAAmD;AACnD,4BAA4B;AAC5B,2DAA2D;AAY3D,OAAO,EAAE,YAAY,EAAyB,MAAM,aAAa,CAAC;AAGlE,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAC7B,MAAM,sBAAsB,G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I,oBAAoB,CAAC;QAC7B,OAAO,EAAE,mCAAmC,GAAG,uBAAuB,QAAQ,CAAC,MAAM,EAAE;QACvF,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,GAAG;QACH,YAAY,EAAE,IAAI;QAClB,IAAI,EAAE,MAAM;KACb,CAAC,CAAC;AACL,CAAC;AAED,SAAS,WAAW,CAAC,OAAe;IAClC,OAAO,IAAI,oBAAoB,CAAC;QAC9B,OAAO;QACP,MAAM,EAAE,CAAC;QACT,GAAG,EAAE,EAAE;QACP,YAAY,EAAE,IAAI;QAClB,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { DataAdapter, ListParams, ListResult, RelationOption, ResourceId, SearchRelationParams } from '@kozou/core';
|
|
2
|
+
import { AdapterError, type AdapterErrorInit } from './errors.js';
|
|
3
|
+
import type { FetchLike } from './types.js';
|
|
4
|
+
/** A single key column, the ordered columns of a composite key, or a
|
|
5
|
+
* function computing either from the resource name. */
|
|
6
|
+
export type PostgrestPrimaryKeyResolver = string | string[] | ((resource: string) => string | string[]);
|
|
7
|
+
export interface PostgrestAdapterOptions {
|
|
8
|
+
/** Base URL of the PostgREST server (trailing slash is stripped). */
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
/** Default DB schema; non-default schemas are addressed via the
|
|
11
|
+
* resource string `<schema>.<table>` plus per-request profile headers. */
|
|
12
|
+
defaultSchema?: string;
|
|
13
|
+
/** Primary key resolver. A plain string is used for every resource;
|
|
14
|
+
* a function lets callers compute the column from the resource name. */
|
|
15
|
+
primaryKey?: PostgrestPrimaryKeyResolver;
|
|
16
|
+
/** Static headers merged into every request (e.g. Authorization). */
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
/** Fetch override; defaults to `globalThis.fetch`. Injection point for tests. */
|
|
19
|
+
fetch?: FetchLike;
|
|
20
|
+
/** Page size used when ListParams.pageSize is omitted. */
|
|
21
|
+
defaultPageSize?: number;
|
|
22
|
+
}
|
|
23
|
+
export declare class PostgrestAdapterError extends AdapterError {
|
|
24
|
+
constructor(init: AdapterErrorInit);
|
|
25
|
+
}
|
|
26
|
+
export declare class PostgrestDataAdapter implements DataAdapter {
|
|
27
|
+
private readonly baseUrl;
|
|
28
|
+
private readonly defaultSchema;
|
|
29
|
+
private readonly resolvePrimaryKey;
|
|
30
|
+
private readonly staticHeaders;
|
|
31
|
+
private readonly fetchImpl;
|
|
32
|
+
private readonly defaultPageSize;
|
|
33
|
+
constructor(opts: PostgrestAdapterOptions);
|
|
34
|
+
list(resource: string, params: ListParams): Promise<ListResult>;
|
|
35
|
+
get(resource: string, id: ResourceId): Promise<Record<string, unknown>>;
|
|
36
|
+
create(resource: string, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
37
|
+
update(resource: string, id: ResourceId, data: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
38
|
+
delete(resource: string, id: ResourceId): Promise<void>;
|
|
39
|
+
searchRelation(resource: string, params: SearchRelationParams): Promise<RelationOption[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Append the per-column equality filters that address a row by id. A
|
|
42
|
+
* composite key expands to `?col0=eq.v0&col1=eq.v1` in `primaryKey`
|
|
43
|
+
* declaration order; a single-column key keeps
|
|
44
|
+
* the `?col=eq.value` form. The id component count must match the key
|
|
45
|
+
* arity (else a config error, surfacing a wiring mismatch).
|
|
46
|
+
*/
|
|
47
|
+
private appendKeyEquals;
|
|
48
|
+
private mutationHeaders;
|
|
49
|
+
private send;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=postgrest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgrest.d.ts","sourceRoot":"","sources":["../../src/adapter/postgrest.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,UAAU,EACV,cAAc,EACd,UAAU,EACV,oBAAoB,EAErB,MAAM,aAAa,CAAC;A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