@voyantjs/external-refs 0.1.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 +109 -0
- package/README.md +34 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/routes.d.ts +253 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +51 -0
- package/dist/schema.d.ts +251 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +30 -0
- package/dist/service.d.ts +82 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +112 -0
- package/dist/validation.d.ts +91 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +40 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, Apache 2.0 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 PixelMakers Studio SRL
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly
|
|
28
|
+
display and redistribute the Software for any Permitted Purpose identified
|
|
29
|
+
below.
|
|
30
|
+
|
|
31
|
+
### Permitted Purpose
|
|
32
|
+
|
|
33
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing
|
|
34
|
+
Use means making the Software available to others in a commercial product or
|
|
35
|
+
service that:
|
|
36
|
+
|
|
37
|
+
1. substitutes for the Software;
|
|
38
|
+
|
|
39
|
+
2. substitutes for any other product or service we offer using the Software
|
|
40
|
+
that exists as of the date we make the Software available; or
|
|
41
|
+
|
|
42
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
43
|
+
|
|
44
|
+
Permitted Purposes specifically include using the Software:
|
|
45
|
+
|
|
46
|
+
1. for your internal use and access;
|
|
47
|
+
|
|
48
|
+
2. for non-commercial education;
|
|
49
|
+
|
|
50
|
+
3. for non-commercial research; and
|
|
51
|
+
|
|
52
|
+
4. in connection with professional services that you provide to a licensee
|
|
53
|
+
using the Software in accordance with these Terms and Conditions.
|
|
54
|
+
|
|
55
|
+
### Patents
|
|
56
|
+
|
|
57
|
+
To the extent your use for a Permitted Purpose would necessarily infringe
|
|
58
|
+
our patents, the license grant above includes a license under our patents.
|
|
59
|
+
If you make a claim against any party that the Software infringes or
|
|
60
|
+
contributes to the infringement of any patent, then your patent license to
|
|
61
|
+
the Software ends immediately.
|
|
62
|
+
|
|
63
|
+
### Redistribution
|
|
64
|
+
|
|
65
|
+
The Terms and Conditions apply to all copies, modifications and derivatives
|
|
66
|
+
of the Software.
|
|
67
|
+
|
|
68
|
+
If you redistribute any copies, modifications or derivatives of the
|
|
69
|
+
Software, you must include a copy of or a link to these Terms and Conditions
|
|
70
|
+
and not remove any copyright notices provided in or with the Software.
|
|
71
|
+
|
|
72
|
+
### Disclaimer
|
|
73
|
+
|
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS
|
|
75
|
+
OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A
|
|
76
|
+
PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
77
|
+
|
|
78
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO
|
|
79
|
+
THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
|
|
80
|
+
DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
81
|
+
|
|
82
|
+
### Trademarks
|
|
83
|
+
|
|
84
|
+
Except for displaying the License Details and identifying us as the origin
|
|
85
|
+
of the Software, you have no right under these Terms and Conditions to use
|
|
86
|
+
our trademarks, trade names, service marks or product names.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Grant of Future License
|
|
91
|
+
|
|
92
|
+
We hereby irrevocably grant you an additional license to use the Software
|
|
93
|
+
under the Apache License, Version 2.0 that is effective on the second
|
|
94
|
+
anniversary of the date we make the Software available. On or after that
|
|
95
|
+
date, you may use the Software under the Apache License, Version 2.0, in
|
|
96
|
+
which case the following will apply:
|
|
97
|
+
|
|
98
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
99
|
+
use this file except in compliance with the License.
|
|
100
|
+
|
|
101
|
+
You may obtain a copy of the License at
|
|
102
|
+
|
|
103
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
104
|
+
|
|
105
|
+
Unless required by applicable law or agreed to in writing, software
|
|
106
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
107
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
108
|
+
License for the specific language governing permissions and limitations
|
|
109
|
+
under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @voyantjs/external-refs
|
|
2
|
+
|
|
3
|
+
External references module for Voyant. Cross-system external identity and mapping layer — correlates Voyant entities with IDs in third-party systems (channels, PMSs, OTAs).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @voyantjs/external-refs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { externalRefsModule } from "@voyantjs/external-refs"
|
|
15
|
+
import { createApp } from "@voyantjs/hono"
|
|
16
|
+
|
|
17
|
+
const app = createApp({
|
|
18
|
+
modules: [externalRefsModule],
|
|
19
|
+
// ...
|
|
20
|
+
})
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Exports
|
|
24
|
+
|
|
25
|
+
| Entry | Description |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `.` | Module export |
|
|
28
|
+
| `./schema` | Drizzle tables |
|
|
29
|
+
| `./validation` | Zod schemas |
|
|
30
|
+
| `./routes` | Hono routes |
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
FSL-1.1-Apache-2.0
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Module } from "@voyantjs/core";
|
|
2
|
+
import type { HonoModule } from "@voyantjs/hono/module";
|
|
3
|
+
import { externalRefsService } from "./service.js";
|
|
4
|
+
export type { ExternalRefsRoutes } from "./routes.js";
|
|
5
|
+
export declare const externalRefsModule: Module;
|
|
6
|
+
export declare const externalRefsHonoModule: HonoModule;
|
|
7
|
+
export type { ExternalRef, NewExternalRef } from "./schema.js";
|
|
8
|
+
export { externalRefStatusEnum, externalRefs } from "./schema.js";
|
|
9
|
+
export { externalRefListQuerySchema, externalRefStatusSchema, insertExternalRefForEntitySchema, insertExternalRefSchema, selectExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
|
|
10
|
+
export { externalRefsService };
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAGvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAElD,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,eAAO,MAAM,kBAAkB,EAAE,MAEhC,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,UAGpC,CAAA;AAED,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACjE,OAAO,EACL,0BAA0B,EAC1B,uBAAuB,EACvB,gCAAgC,EAChC,uBAAuB,EACvB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { externalRefsRoutes } from "./routes.js";
|
|
2
|
+
import { externalRefsService } from "./service.js";
|
|
3
|
+
export const externalRefsModule = {
|
|
4
|
+
name: "external-refs",
|
|
5
|
+
};
|
|
6
|
+
export const externalRefsHonoModule = {
|
|
7
|
+
module: externalRefsModule,
|
|
8
|
+
routes: externalRefsRoutes,
|
|
9
|
+
};
|
|
10
|
+
export { externalRefStatusEnum, externalRefs } from "./schema.js";
|
|
11
|
+
export { externalRefListQuerySchema, externalRefStatusSchema, insertExternalRefForEntitySchema, insertExternalRefSchema, selectExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
|
|
12
|
+
export { externalRefsService };
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
type Env = {
|
|
3
|
+
Variables: {
|
|
4
|
+
db: PostgresJsDatabase;
|
|
5
|
+
userId?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const externalRefsRoutes: import("hono/hono-base").HonoBase<Env, {
|
|
9
|
+
"/refs": {
|
|
10
|
+
$get: {
|
|
11
|
+
input: {};
|
|
12
|
+
output: {
|
|
13
|
+
data: {
|
|
14
|
+
id: string;
|
|
15
|
+
entityType: string;
|
|
16
|
+
entityId: string;
|
|
17
|
+
sourceSystem: string;
|
|
18
|
+
objectType: string;
|
|
19
|
+
namespace: string;
|
|
20
|
+
externalId: string;
|
|
21
|
+
externalParentId: string | null;
|
|
22
|
+
isPrimary: boolean;
|
|
23
|
+
status: "active" | "inactive" | "archived";
|
|
24
|
+
lastSyncedAt: string | null;
|
|
25
|
+
metadata: {
|
|
26
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
27
|
+
} | null;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
updatedAt: string;
|
|
30
|
+
}[];
|
|
31
|
+
total: number;
|
|
32
|
+
limit: number;
|
|
33
|
+
offset: number;
|
|
34
|
+
};
|
|
35
|
+
outputFormat: "json";
|
|
36
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
} & {
|
|
40
|
+
"/refs": {
|
|
41
|
+
$post: {
|
|
42
|
+
input: {};
|
|
43
|
+
output: {
|
|
44
|
+
data: {
|
|
45
|
+
id: string;
|
|
46
|
+
entityType: string;
|
|
47
|
+
entityId: string;
|
|
48
|
+
sourceSystem: string;
|
|
49
|
+
objectType: string;
|
|
50
|
+
namespace: string;
|
|
51
|
+
externalId: string;
|
|
52
|
+
externalParentId: string | null;
|
|
53
|
+
isPrimary: boolean;
|
|
54
|
+
status: "active" | "inactive" | "archived";
|
|
55
|
+
lastSyncedAt: string | null;
|
|
56
|
+
metadata: {
|
|
57
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
58
|
+
} | null;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
updatedAt: string;
|
|
61
|
+
} | null;
|
|
62
|
+
};
|
|
63
|
+
outputFormat: "json";
|
|
64
|
+
status: 201;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
} & {
|
|
68
|
+
"/refs/:id": {
|
|
69
|
+
$get: {
|
|
70
|
+
input: {
|
|
71
|
+
param: {
|
|
72
|
+
id: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
output: {
|
|
76
|
+
error: string;
|
|
77
|
+
};
|
|
78
|
+
outputFormat: "json";
|
|
79
|
+
status: 404;
|
|
80
|
+
} | {
|
|
81
|
+
input: {
|
|
82
|
+
param: {
|
|
83
|
+
id: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
output: {
|
|
87
|
+
data: {
|
|
88
|
+
id: string;
|
|
89
|
+
entityType: string;
|
|
90
|
+
entityId: string;
|
|
91
|
+
sourceSystem: string;
|
|
92
|
+
objectType: string;
|
|
93
|
+
namespace: string;
|
|
94
|
+
externalId: string;
|
|
95
|
+
externalParentId: string | null;
|
|
96
|
+
isPrimary: boolean;
|
|
97
|
+
status: "active" | "inactive" | "archived";
|
|
98
|
+
lastSyncedAt: string | null;
|
|
99
|
+
metadata: {
|
|
100
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
101
|
+
} | null;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
updatedAt: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
outputFormat: "json";
|
|
107
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
} & {
|
|
111
|
+
"/refs/:id": {
|
|
112
|
+
$patch: {
|
|
113
|
+
input: {
|
|
114
|
+
param: {
|
|
115
|
+
id: string;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
output: {
|
|
119
|
+
error: string;
|
|
120
|
+
};
|
|
121
|
+
outputFormat: "json";
|
|
122
|
+
status: 404;
|
|
123
|
+
} | {
|
|
124
|
+
input: {
|
|
125
|
+
param: {
|
|
126
|
+
id: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
output: {
|
|
130
|
+
data: {
|
|
131
|
+
id: string;
|
|
132
|
+
entityType: string;
|
|
133
|
+
entityId: string;
|
|
134
|
+
sourceSystem: string;
|
|
135
|
+
objectType: string;
|
|
136
|
+
namespace: string;
|
|
137
|
+
externalId: string;
|
|
138
|
+
externalParentId: string | null;
|
|
139
|
+
isPrimary: boolean;
|
|
140
|
+
status: "active" | "inactive" | "archived";
|
|
141
|
+
lastSyncedAt: string | null;
|
|
142
|
+
metadata: {
|
|
143
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
144
|
+
} | null;
|
|
145
|
+
createdAt: string;
|
|
146
|
+
updatedAt: string;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
outputFormat: "json";
|
|
150
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
} & {
|
|
154
|
+
"/refs/:id": {
|
|
155
|
+
$delete: {
|
|
156
|
+
input: {
|
|
157
|
+
param: {
|
|
158
|
+
id: string;
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
output: {
|
|
162
|
+
error: string;
|
|
163
|
+
};
|
|
164
|
+
outputFormat: "json";
|
|
165
|
+
status: 404;
|
|
166
|
+
} | {
|
|
167
|
+
input: {
|
|
168
|
+
param: {
|
|
169
|
+
id: string;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
output: {
|
|
173
|
+
success: true;
|
|
174
|
+
};
|
|
175
|
+
outputFormat: "json";
|
|
176
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
} & {
|
|
180
|
+
"/entities/:entityType/:entityId/refs": {
|
|
181
|
+
$get: {
|
|
182
|
+
input: {
|
|
183
|
+
param: {
|
|
184
|
+
entityType: string;
|
|
185
|
+
} & {
|
|
186
|
+
entityId: string;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
output: {
|
|
190
|
+
data: {
|
|
191
|
+
id: string;
|
|
192
|
+
entityType: string;
|
|
193
|
+
entityId: string;
|
|
194
|
+
sourceSystem: string;
|
|
195
|
+
objectType: string;
|
|
196
|
+
namespace: string;
|
|
197
|
+
externalId: string;
|
|
198
|
+
externalParentId: string | null;
|
|
199
|
+
isPrimary: boolean;
|
|
200
|
+
status: "active" | "inactive" | "archived";
|
|
201
|
+
lastSyncedAt: string | null;
|
|
202
|
+
metadata: {
|
|
203
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
204
|
+
} | null;
|
|
205
|
+
createdAt: string;
|
|
206
|
+
updatedAt: string;
|
|
207
|
+
}[];
|
|
208
|
+
total: number;
|
|
209
|
+
limit: number;
|
|
210
|
+
offset: number;
|
|
211
|
+
};
|
|
212
|
+
outputFormat: "json";
|
|
213
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
} & {
|
|
217
|
+
"/entities/:entityType/:entityId/refs": {
|
|
218
|
+
$post: {
|
|
219
|
+
input: {
|
|
220
|
+
param: {
|
|
221
|
+
entityType: string;
|
|
222
|
+
} & {
|
|
223
|
+
entityId: string;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
output: {
|
|
227
|
+
data: {
|
|
228
|
+
id: string;
|
|
229
|
+
entityType: string;
|
|
230
|
+
entityId: string;
|
|
231
|
+
sourceSystem: string;
|
|
232
|
+
objectType: string;
|
|
233
|
+
namespace: string;
|
|
234
|
+
externalId: string;
|
|
235
|
+
externalParentId: string | null;
|
|
236
|
+
isPrimary: boolean;
|
|
237
|
+
status: "active" | "inactive" | "archived";
|
|
238
|
+
lastSyncedAt: string | null;
|
|
239
|
+
metadata: {
|
|
240
|
+
[x: string]: import("hono/utils/types").JSONValue;
|
|
241
|
+
} | null;
|
|
242
|
+
createdAt: string;
|
|
243
|
+
updatedAt: string;
|
|
244
|
+
} | null;
|
|
245
|
+
};
|
|
246
|
+
outputFormat: "json";
|
|
247
|
+
status: 201;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
}, "/", "/entities/:entityType/:entityId/refs">;
|
|
251
|
+
export type ExternalRefsRoutes = typeof externalRefsRoutes;
|
|
252
|
+
export {};
|
|
253
|
+
//# sourceMappingURL=routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAWjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CA2D3B,CAAA;AAEJ,MAAM,MAAM,kBAAkB,GAAG,OAAO,kBAAkB,CAAA"}
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { externalRefsService } from "./service.js";
|
|
3
|
+
import { externalRefListQuerySchema, insertExternalRefForEntitySchema, insertExternalRefSchema, updateExternalRefSchema, } from "./validation.js";
|
|
4
|
+
export const externalRefsRoutes = new Hono()
|
|
5
|
+
.get("/refs", async (c) => {
|
|
6
|
+
const query = externalRefListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
7
|
+
return c.json(await externalRefsService.listExternalRefs(c.get("db"), query));
|
|
8
|
+
})
|
|
9
|
+
.post("/refs", async (c) => {
|
|
10
|
+
return c.json({
|
|
11
|
+
data: await externalRefsService.createExternalRef(c.get("db"), insertExternalRefSchema.parse(await c.req.json())),
|
|
12
|
+
}, 201);
|
|
13
|
+
})
|
|
14
|
+
.get("/refs/:id", async (c) => {
|
|
15
|
+
const row = await externalRefsService.getExternalRefById(c.get("db"), c.req.param("id"));
|
|
16
|
+
if (!row)
|
|
17
|
+
return c.json({ error: "External reference not found" }, 404);
|
|
18
|
+
return c.json({ data: row });
|
|
19
|
+
})
|
|
20
|
+
.patch("/refs/:id", async (c) => {
|
|
21
|
+
const row = await externalRefsService.updateExternalRef(c.get("db"), c.req.param("id"), updateExternalRefSchema.parse(await c.req.json()));
|
|
22
|
+
if (!row)
|
|
23
|
+
return c.json({ error: "External reference not found" }, 404);
|
|
24
|
+
return c.json({ data: row });
|
|
25
|
+
})
|
|
26
|
+
.delete("/refs/:id", async (c) => {
|
|
27
|
+
const row = await externalRefsService.deleteExternalRef(c.get("db"), c.req.param("id"));
|
|
28
|
+
if (!row)
|
|
29
|
+
return c.json({ error: "External reference not found" }, 404);
|
|
30
|
+
return c.json({ success: true });
|
|
31
|
+
})
|
|
32
|
+
.get("/entities/:entityType/:entityId/refs", async (c) => {
|
|
33
|
+
const params = c.req.param();
|
|
34
|
+
const query = externalRefListQuerySchema.parse({
|
|
35
|
+
...Object.fromEntries(new URL(c.req.url).searchParams),
|
|
36
|
+
entityType: params.entityType,
|
|
37
|
+
entityId: params.entityId,
|
|
38
|
+
});
|
|
39
|
+
return c.json(await externalRefsService.listExternalRefs(c.get("db"), query));
|
|
40
|
+
})
|
|
41
|
+
.post("/entities/:entityType/:entityId/refs", async (c) => {
|
|
42
|
+
const params = c.req.param();
|
|
43
|
+
const body = insertExternalRefForEntitySchema.parse(await c.req.json());
|
|
44
|
+
return c.json({
|
|
45
|
+
data: await externalRefsService.createExternalRef(c.get("db"), {
|
|
46
|
+
...body,
|
|
47
|
+
entityType: params.entityType,
|
|
48
|
+
entityId: params.entityId,
|
|
49
|
+
}),
|
|
50
|
+
}, 201);
|
|
51
|
+
});
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
export declare const externalRefStatusEnum: import("drizzle-orm/pg-core").PgEnum<["active", "inactive", "archived"]>;
|
|
2
|
+
export declare const externalRefs: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
3
|
+
name: "external_refs";
|
|
4
|
+
schema: undefined;
|
|
5
|
+
columns: {
|
|
6
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
7
|
+
name: string;
|
|
8
|
+
tableName: "external_refs";
|
|
9
|
+
dataType: "string";
|
|
10
|
+
columnType: "PgText";
|
|
11
|
+
data: string;
|
|
12
|
+
driverParam: string;
|
|
13
|
+
notNull: true;
|
|
14
|
+
hasDefault: true;
|
|
15
|
+
isPrimaryKey: true;
|
|
16
|
+
isAutoincrement: false;
|
|
17
|
+
hasRuntimeDefault: true;
|
|
18
|
+
enumValues: [string, ...string[]];
|
|
19
|
+
baseColumn: never;
|
|
20
|
+
identity: undefined;
|
|
21
|
+
generated: undefined;
|
|
22
|
+
}, {}, {}>;
|
|
23
|
+
entityType: import("drizzle-orm/pg-core").PgColumn<{
|
|
24
|
+
name: "entity_type";
|
|
25
|
+
tableName: "external_refs";
|
|
26
|
+
dataType: "string";
|
|
27
|
+
columnType: "PgText";
|
|
28
|
+
data: string;
|
|
29
|
+
driverParam: string;
|
|
30
|
+
notNull: true;
|
|
31
|
+
hasDefault: false;
|
|
32
|
+
isPrimaryKey: false;
|
|
33
|
+
isAutoincrement: false;
|
|
34
|
+
hasRuntimeDefault: false;
|
|
35
|
+
enumValues: [string, ...string[]];
|
|
36
|
+
baseColumn: never;
|
|
37
|
+
identity: undefined;
|
|
38
|
+
generated: undefined;
|
|
39
|
+
}, {}, {}>;
|
|
40
|
+
entityId: import("drizzle-orm/pg-core").PgColumn<{
|
|
41
|
+
name: "entity_id";
|
|
42
|
+
tableName: "external_refs";
|
|
43
|
+
dataType: "string";
|
|
44
|
+
columnType: "PgText";
|
|
45
|
+
data: string;
|
|
46
|
+
driverParam: string;
|
|
47
|
+
notNull: true;
|
|
48
|
+
hasDefault: false;
|
|
49
|
+
isPrimaryKey: false;
|
|
50
|
+
isAutoincrement: false;
|
|
51
|
+
hasRuntimeDefault: false;
|
|
52
|
+
enumValues: [string, ...string[]];
|
|
53
|
+
baseColumn: never;
|
|
54
|
+
identity: undefined;
|
|
55
|
+
generated: undefined;
|
|
56
|
+
}, {}, {}>;
|
|
57
|
+
sourceSystem: import("drizzle-orm/pg-core").PgColumn<{
|
|
58
|
+
name: "source_system";
|
|
59
|
+
tableName: "external_refs";
|
|
60
|
+
dataType: "string";
|
|
61
|
+
columnType: "PgText";
|
|
62
|
+
data: string;
|
|
63
|
+
driverParam: string;
|
|
64
|
+
notNull: true;
|
|
65
|
+
hasDefault: false;
|
|
66
|
+
isPrimaryKey: false;
|
|
67
|
+
isAutoincrement: false;
|
|
68
|
+
hasRuntimeDefault: false;
|
|
69
|
+
enumValues: [string, ...string[]];
|
|
70
|
+
baseColumn: never;
|
|
71
|
+
identity: undefined;
|
|
72
|
+
generated: undefined;
|
|
73
|
+
}, {}, {}>;
|
|
74
|
+
objectType: import("drizzle-orm/pg-core").PgColumn<{
|
|
75
|
+
name: "object_type";
|
|
76
|
+
tableName: "external_refs";
|
|
77
|
+
dataType: "string";
|
|
78
|
+
columnType: "PgText";
|
|
79
|
+
data: string;
|
|
80
|
+
driverParam: string;
|
|
81
|
+
notNull: true;
|
|
82
|
+
hasDefault: false;
|
|
83
|
+
isPrimaryKey: false;
|
|
84
|
+
isAutoincrement: false;
|
|
85
|
+
hasRuntimeDefault: false;
|
|
86
|
+
enumValues: [string, ...string[]];
|
|
87
|
+
baseColumn: never;
|
|
88
|
+
identity: undefined;
|
|
89
|
+
generated: undefined;
|
|
90
|
+
}, {}, {}>;
|
|
91
|
+
namespace: import("drizzle-orm/pg-core").PgColumn<{
|
|
92
|
+
name: "namespace";
|
|
93
|
+
tableName: "external_refs";
|
|
94
|
+
dataType: "string";
|
|
95
|
+
columnType: "PgText";
|
|
96
|
+
data: string;
|
|
97
|
+
driverParam: string;
|
|
98
|
+
notNull: true;
|
|
99
|
+
hasDefault: true;
|
|
100
|
+
isPrimaryKey: false;
|
|
101
|
+
isAutoincrement: false;
|
|
102
|
+
hasRuntimeDefault: false;
|
|
103
|
+
enumValues: [string, ...string[]];
|
|
104
|
+
baseColumn: never;
|
|
105
|
+
identity: undefined;
|
|
106
|
+
generated: undefined;
|
|
107
|
+
}, {}, {}>;
|
|
108
|
+
externalId: import("drizzle-orm/pg-core").PgColumn<{
|
|
109
|
+
name: "external_id";
|
|
110
|
+
tableName: "external_refs";
|
|
111
|
+
dataType: "string";
|
|
112
|
+
columnType: "PgText";
|
|
113
|
+
data: string;
|
|
114
|
+
driverParam: string;
|
|
115
|
+
notNull: true;
|
|
116
|
+
hasDefault: false;
|
|
117
|
+
isPrimaryKey: false;
|
|
118
|
+
isAutoincrement: false;
|
|
119
|
+
hasRuntimeDefault: false;
|
|
120
|
+
enumValues: [string, ...string[]];
|
|
121
|
+
baseColumn: never;
|
|
122
|
+
identity: undefined;
|
|
123
|
+
generated: undefined;
|
|
124
|
+
}, {}, {}>;
|
|
125
|
+
externalParentId: import("drizzle-orm/pg-core").PgColumn<{
|
|
126
|
+
name: "external_parent_id";
|
|
127
|
+
tableName: "external_refs";
|
|
128
|
+
dataType: "string";
|
|
129
|
+
columnType: "PgText";
|
|
130
|
+
data: string;
|
|
131
|
+
driverParam: string;
|
|
132
|
+
notNull: false;
|
|
133
|
+
hasDefault: false;
|
|
134
|
+
isPrimaryKey: false;
|
|
135
|
+
isAutoincrement: false;
|
|
136
|
+
hasRuntimeDefault: false;
|
|
137
|
+
enumValues: [string, ...string[]];
|
|
138
|
+
baseColumn: never;
|
|
139
|
+
identity: undefined;
|
|
140
|
+
generated: undefined;
|
|
141
|
+
}, {}, {}>;
|
|
142
|
+
isPrimary: import("drizzle-orm/pg-core").PgColumn<{
|
|
143
|
+
name: "is_primary";
|
|
144
|
+
tableName: "external_refs";
|
|
145
|
+
dataType: "boolean";
|
|
146
|
+
columnType: "PgBoolean";
|
|
147
|
+
data: boolean;
|
|
148
|
+
driverParam: boolean;
|
|
149
|
+
notNull: true;
|
|
150
|
+
hasDefault: true;
|
|
151
|
+
isPrimaryKey: false;
|
|
152
|
+
isAutoincrement: false;
|
|
153
|
+
hasRuntimeDefault: false;
|
|
154
|
+
enumValues: undefined;
|
|
155
|
+
baseColumn: never;
|
|
156
|
+
identity: undefined;
|
|
157
|
+
generated: undefined;
|
|
158
|
+
}, {}, {}>;
|
|
159
|
+
status: import("drizzle-orm/pg-core").PgColumn<{
|
|
160
|
+
name: "status";
|
|
161
|
+
tableName: "external_refs";
|
|
162
|
+
dataType: "string";
|
|
163
|
+
columnType: "PgEnumColumn";
|
|
164
|
+
data: "active" | "inactive" | "archived";
|
|
165
|
+
driverParam: string;
|
|
166
|
+
notNull: true;
|
|
167
|
+
hasDefault: true;
|
|
168
|
+
isPrimaryKey: false;
|
|
169
|
+
isAutoincrement: false;
|
|
170
|
+
hasRuntimeDefault: false;
|
|
171
|
+
enumValues: ["active", "inactive", "archived"];
|
|
172
|
+
baseColumn: never;
|
|
173
|
+
identity: undefined;
|
|
174
|
+
generated: undefined;
|
|
175
|
+
}, {}, {}>;
|
|
176
|
+
lastSyncedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
177
|
+
name: "last_synced_at";
|
|
178
|
+
tableName: "external_refs";
|
|
179
|
+
dataType: "date";
|
|
180
|
+
columnType: "PgTimestamp";
|
|
181
|
+
data: Date;
|
|
182
|
+
driverParam: string;
|
|
183
|
+
notNull: false;
|
|
184
|
+
hasDefault: false;
|
|
185
|
+
isPrimaryKey: false;
|
|
186
|
+
isAutoincrement: false;
|
|
187
|
+
hasRuntimeDefault: false;
|
|
188
|
+
enumValues: undefined;
|
|
189
|
+
baseColumn: never;
|
|
190
|
+
identity: undefined;
|
|
191
|
+
generated: undefined;
|
|
192
|
+
}, {}, {}>;
|
|
193
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
194
|
+
name: "metadata";
|
|
195
|
+
tableName: "external_refs";
|
|
196
|
+
dataType: "json";
|
|
197
|
+
columnType: "PgJsonb";
|
|
198
|
+
data: Record<string, unknown>;
|
|
199
|
+
driverParam: unknown;
|
|
200
|
+
notNull: false;
|
|
201
|
+
hasDefault: false;
|
|
202
|
+
isPrimaryKey: false;
|
|
203
|
+
isAutoincrement: false;
|
|
204
|
+
hasRuntimeDefault: false;
|
|
205
|
+
enumValues: undefined;
|
|
206
|
+
baseColumn: never;
|
|
207
|
+
identity: undefined;
|
|
208
|
+
generated: undefined;
|
|
209
|
+
}, {}, {
|
|
210
|
+
$type: Record<string, unknown>;
|
|
211
|
+
}>;
|
|
212
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
213
|
+
name: "created_at";
|
|
214
|
+
tableName: "external_refs";
|
|
215
|
+
dataType: "date";
|
|
216
|
+
columnType: "PgTimestamp";
|
|
217
|
+
data: Date;
|
|
218
|
+
driverParam: string;
|
|
219
|
+
notNull: true;
|
|
220
|
+
hasDefault: true;
|
|
221
|
+
isPrimaryKey: false;
|
|
222
|
+
isAutoincrement: false;
|
|
223
|
+
hasRuntimeDefault: false;
|
|
224
|
+
enumValues: undefined;
|
|
225
|
+
baseColumn: never;
|
|
226
|
+
identity: undefined;
|
|
227
|
+
generated: undefined;
|
|
228
|
+
}, {}, {}>;
|
|
229
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
230
|
+
name: "updated_at";
|
|
231
|
+
tableName: "external_refs";
|
|
232
|
+
dataType: "date";
|
|
233
|
+
columnType: "PgTimestamp";
|
|
234
|
+
data: Date;
|
|
235
|
+
driverParam: string;
|
|
236
|
+
notNull: true;
|
|
237
|
+
hasDefault: true;
|
|
238
|
+
isPrimaryKey: false;
|
|
239
|
+
isAutoincrement: false;
|
|
240
|
+
hasRuntimeDefault: false;
|
|
241
|
+
enumValues: undefined;
|
|
242
|
+
baseColumn: never;
|
|
243
|
+
identity: undefined;
|
|
244
|
+
generated: undefined;
|
|
245
|
+
}, {}, {}>;
|
|
246
|
+
};
|
|
247
|
+
dialect: "pg";
|
|
248
|
+
}>;
|
|
249
|
+
export type ExternalRef = typeof externalRefs.$inferSelect;
|
|
250
|
+
export type NewExternalRef = typeof externalRefs.$inferInsert;
|
|
251
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,qBAAqB,0EAIhC,CAAA;AAEF,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCxB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,OAAO,YAAY,CAAC,YAAY,CAAA;AAC1D,MAAM,MAAM,cAAc,GAAG,OAAO,YAAY,CAAC,YAAY,CAAA"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { typeId } from "@voyantjs/db/lib/typeid-column";
|
|
2
|
+
import { boolean, index, jsonb, pgEnum, pgTable, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
3
|
+
export const externalRefStatusEnum = pgEnum("external_ref_status", [
|
|
4
|
+
"active",
|
|
5
|
+
"inactive",
|
|
6
|
+
"archived",
|
|
7
|
+
]);
|
|
8
|
+
export const externalRefs = pgTable("external_refs", {
|
|
9
|
+
id: typeId("external_refs"),
|
|
10
|
+
entityType: text("entity_type").notNull(),
|
|
11
|
+
entityId: text("entity_id").notNull(),
|
|
12
|
+
sourceSystem: text("source_system").notNull(),
|
|
13
|
+
objectType: text("object_type").notNull(),
|
|
14
|
+
namespace: text("namespace").notNull().default("default"),
|
|
15
|
+
externalId: text("external_id").notNull(),
|
|
16
|
+
externalParentId: text("external_parent_id"),
|
|
17
|
+
isPrimary: boolean("is_primary").notNull().default(false),
|
|
18
|
+
status: externalRefStatusEnum("status").notNull().default("active"),
|
|
19
|
+
lastSyncedAt: timestamp("last_synced_at", { withTimezone: true }),
|
|
20
|
+
metadata: jsonb("metadata").$type(),
|
|
21
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
22
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
23
|
+
}, (table) => [
|
|
24
|
+
index("idx_external_refs_entity").on(table.entityType, table.entityId),
|
|
25
|
+
index("idx_external_refs_source").on(table.sourceSystem, table.objectType),
|
|
26
|
+
index("idx_external_refs_external_id").on(table.externalId),
|
|
27
|
+
index("idx_external_refs_status").on(table.status),
|
|
28
|
+
uniqueIndex("uidx_external_refs_entity_source_external").on(table.entityType, table.entityId, table.sourceSystem, table.namespace, table.externalId),
|
|
29
|
+
uniqueIndex("uidx_external_refs_source_object_external").on(table.sourceSystem, table.objectType, table.namespace, table.externalId),
|
|
30
|
+
]);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import type { externalRefListQuerySchema, insertExternalRefSchema, updateExternalRefSchema } from "./validation.js";
|
|
4
|
+
type ExternalRefListQuery = z.infer<typeof externalRefListQuerySchema>;
|
|
5
|
+
type CreateExternalRefInput = z.infer<typeof insertExternalRefSchema>;
|
|
6
|
+
type UpdateExternalRefInput = z.infer<typeof updateExternalRefSchema>;
|
|
7
|
+
export declare const externalRefsService: {
|
|
8
|
+
listExternalRefs(db: PostgresJsDatabase, query: ExternalRefListQuery): Promise<{
|
|
9
|
+
data: {
|
|
10
|
+
id: string;
|
|
11
|
+
entityType: string;
|
|
12
|
+
entityId: string;
|
|
13
|
+
sourceSystem: string;
|
|
14
|
+
objectType: string;
|
|
15
|
+
namespace: string;
|
|
16
|
+
externalId: string;
|
|
17
|
+
externalParentId: string | null;
|
|
18
|
+
isPrimary: boolean;
|
|
19
|
+
status: "active" | "inactive" | "archived";
|
|
20
|
+
lastSyncedAt: Date | null;
|
|
21
|
+
metadata: Record<string, unknown> | null;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
}[];
|
|
25
|
+
total: number;
|
|
26
|
+
limit: number;
|
|
27
|
+
offset: number;
|
|
28
|
+
}>;
|
|
29
|
+
getExternalRefById(db: PostgresJsDatabase, id: string): Promise<{
|
|
30
|
+
id: string;
|
|
31
|
+
entityType: string;
|
|
32
|
+
entityId: string;
|
|
33
|
+
sourceSystem: string;
|
|
34
|
+
objectType: string;
|
|
35
|
+
namespace: string;
|
|
36
|
+
externalId: string;
|
|
37
|
+
externalParentId: string | null;
|
|
38
|
+
isPrimary: boolean;
|
|
39
|
+
status: "active" | "inactive" | "archived";
|
|
40
|
+
lastSyncedAt: Date | null;
|
|
41
|
+
metadata: Record<string, unknown> | null;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
} | null>;
|
|
45
|
+
createExternalRef(db: PostgresJsDatabase, data: CreateExternalRefInput): Promise<{
|
|
46
|
+
id: string;
|
|
47
|
+
entityType: string;
|
|
48
|
+
entityId: string;
|
|
49
|
+
sourceSystem: string;
|
|
50
|
+
objectType: string;
|
|
51
|
+
namespace: string;
|
|
52
|
+
externalId: string;
|
|
53
|
+
externalParentId: string | null;
|
|
54
|
+
isPrimary: boolean;
|
|
55
|
+
status: "active" | "inactive" | "archived";
|
|
56
|
+
lastSyncedAt: Date | null;
|
|
57
|
+
metadata: Record<string, unknown> | null;
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
updatedAt: Date;
|
|
60
|
+
} | null>;
|
|
61
|
+
updateExternalRef(db: PostgresJsDatabase, id: string, data: UpdateExternalRefInput): Promise<{
|
|
62
|
+
id: string;
|
|
63
|
+
entityType: string;
|
|
64
|
+
entityId: string;
|
|
65
|
+
sourceSystem: string;
|
|
66
|
+
objectType: string;
|
|
67
|
+
namespace: string;
|
|
68
|
+
externalId: string;
|
|
69
|
+
externalParentId: string | null;
|
|
70
|
+
isPrimary: boolean;
|
|
71
|
+
status: "active" | "inactive" | "archived";
|
|
72
|
+
lastSyncedAt: Date | null;
|
|
73
|
+
metadata: Record<string, unknown> | null;
|
|
74
|
+
createdAt: Date;
|
|
75
|
+
updatedAt: Date;
|
|
76
|
+
} | null>;
|
|
77
|
+
deleteExternalRef(db: PostgresJsDatabase, id: string): Promise<{
|
|
78
|
+
id: string;
|
|
79
|
+
} | null>;
|
|
80
|
+
};
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAG5B,OAAO,KAAK,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,iBAAiB,CAAA;AAExB,KAAK,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAA;AACtE,KAAK,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AACrE,KAAK,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAA;AA4BrE,eAAO,MAAM,mBAAmB;yBACH,kBAAkB,SAAS,oBAAoB;;;;;;;;;;;;;;;;;;;;;2BAiC7C,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;0BAK/B,kBAAkB,QAAQ,sBAAsB;;;;;;;;;;;;;;;;0BAqBhD,kBAAkB,MAAM,MAAM,QAAQ,sBAAsB;;;;;;;;;;;;;;;;0BA+B5D,kBAAkB,MAAM,MAAM;;;CAO3D,CAAA"}
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { and, desc, eq, ilike, ne, sql } from "drizzle-orm";
|
|
2
|
+
import { externalRefs } from "./schema.js";
|
|
3
|
+
function toTimestamp(value) {
|
|
4
|
+
return value ? new Date(value) : null;
|
|
5
|
+
}
|
|
6
|
+
async function ensurePrimaryRef(db, params) {
|
|
7
|
+
const conditions = [
|
|
8
|
+
eq(externalRefs.entityType, params.entityType),
|
|
9
|
+
eq(externalRefs.entityId, params.entityId),
|
|
10
|
+
eq(externalRefs.sourceSystem, params.sourceSystem),
|
|
11
|
+
];
|
|
12
|
+
if (params.id)
|
|
13
|
+
conditions.push(ne(externalRefs.id, params.id));
|
|
14
|
+
await db
|
|
15
|
+
.update(externalRefs)
|
|
16
|
+
.set({ isPrimary: false, updatedAt: new Date() })
|
|
17
|
+
.where(and(...conditions));
|
|
18
|
+
}
|
|
19
|
+
export const externalRefsService = {
|
|
20
|
+
async listExternalRefs(db, query) {
|
|
21
|
+
const conditions = [];
|
|
22
|
+
if (query.entityType)
|
|
23
|
+
conditions.push(eq(externalRefs.entityType, query.entityType));
|
|
24
|
+
if (query.entityId)
|
|
25
|
+
conditions.push(eq(externalRefs.entityId, query.entityId));
|
|
26
|
+
if (query.sourceSystem)
|
|
27
|
+
conditions.push(eq(externalRefs.sourceSystem, query.sourceSystem));
|
|
28
|
+
if (query.objectType)
|
|
29
|
+
conditions.push(eq(externalRefs.objectType, query.objectType));
|
|
30
|
+
if (query.namespace)
|
|
31
|
+
conditions.push(eq(externalRefs.namespace, query.namespace));
|
|
32
|
+
if (query.status)
|
|
33
|
+
conditions.push(eq(externalRefs.status, query.status));
|
|
34
|
+
if (query.search) {
|
|
35
|
+
const term = `%${query.search}%`;
|
|
36
|
+
conditions.push(ilike(externalRefs.externalId, term));
|
|
37
|
+
}
|
|
38
|
+
const where = conditions.length > 0 ? and(...conditions) : undefined;
|
|
39
|
+
const [data, countResult] = await Promise.all([
|
|
40
|
+
db
|
|
41
|
+
.select()
|
|
42
|
+
.from(externalRefs)
|
|
43
|
+
.where(where)
|
|
44
|
+
.limit(query.limit)
|
|
45
|
+
.offset(query.offset)
|
|
46
|
+
.orderBy(desc(externalRefs.updatedAt)),
|
|
47
|
+
db.select({ count: sql `count(*)::int` }).from(externalRefs).where(where),
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
data,
|
|
51
|
+
total: countResult[0]?.count ?? 0,
|
|
52
|
+
limit: query.limit,
|
|
53
|
+
offset: query.offset,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
async getExternalRefById(db, id) {
|
|
57
|
+
const [row] = await db.select().from(externalRefs).where(eq(externalRefs.id, id)).limit(1);
|
|
58
|
+
return row ?? null;
|
|
59
|
+
},
|
|
60
|
+
async createExternalRef(db, data) {
|
|
61
|
+
if (data.isPrimary) {
|
|
62
|
+
await ensurePrimaryRef(db, {
|
|
63
|
+
entityType: data.entityType,
|
|
64
|
+
entityId: data.entityId,
|
|
65
|
+
sourceSystem: data.sourceSystem,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const [row] = await db
|
|
69
|
+
.insert(externalRefs)
|
|
70
|
+
.values({
|
|
71
|
+
...data,
|
|
72
|
+
namespace: data.namespace ?? "default",
|
|
73
|
+
lastSyncedAt: toTimestamp(data.lastSyncedAt),
|
|
74
|
+
})
|
|
75
|
+
.returning();
|
|
76
|
+
return row ?? null;
|
|
77
|
+
},
|
|
78
|
+
async updateExternalRef(db, id, data) {
|
|
79
|
+
const existing = await this.getExternalRefById(db, id);
|
|
80
|
+
if (!existing)
|
|
81
|
+
return null;
|
|
82
|
+
const nextEntityType = data.entityType ?? existing.entityType;
|
|
83
|
+
const nextEntityId = data.entityId ?? existing.entityId;
|
|
84
|
+
const nextSourceSystem = data.sourceSystem ?? existing.sourceSystem;
|
|
85
|
+
if (data.isPrimary) {
|
|
86
|
+
await ensurePrimaryRef(db, {
|
|
87
|
+
id,
|
|
88
|
+
entityType: nextEntityType,
|
|
89
|
+
entityId: nextEntityId,
|
|
90
|
+
sourceSystem: nextSourceSystem,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
const [row] = await db
|
|
94
|
+
.update(externalRefs)
|
|
95
|
+
.set({
|
|
96
|
+
...data,
|
|
97
|
+
namespace: data.namespace ?? existing.namespace,
|
|
98
|
+
lastSyncedAt: data.lastSyncedAt === undefined ? undefined : toTimestamp(data.lastSyncedAt),
|
|
99
|
+
updatedAt: new Date(),
|
|
100
|
+
})
|
|
101
|
+
.where(eq(externalRefs.id, id))
|
|
102
|
+
.returning();
|
|
103
|
+
return row ?? null;
|
|
104
|
+
},
|
|
105
|
+
async deleteExternalRef(db, id) {
|
|
106
|
+
const [row] = await db
|
|
107
|
+
.delete(externalRefs)
|
|
108
|
+
.where(eq(externalRefs.id, id))
|
|
109
|
+
.returning({ id: externalRefs.id });
|
|
110
|
+
return row ?? null;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const externalRefStatusSchema: z.ZodEnum<{
|
|
3
|
+
active: "active";
|
|
4
|
+
inactive: "inactive";
|
|
5
|
+
archived: "archived";
|
|
6
|
+
}>;
|
|
7
|
+
export declare const insertExternalRefSchema: z.ZodObject<{
|
|
8
|
+
entityType: z.ZodString;
|
|
9
|
+
entityId: z.ZodString;
|
|
10
|
+
sourceSystem: z.ZodString;
|
|
11
|
+
objectType: z.ZodString;
|
|
12
|
+
namespace: z.ZodDefault<z.ZodString>;
|
|
13
|
+
externalId: z.ZodString;
|
|
14
|
+
externalParentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
15
|
+
isPrimary: z.ZodDefault<z.ZodBoolean>;
|
|
16
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
17
|
+
active: "active";
|
|
18
|
+
inactive: "inactive";
|
|
19
|
+
archived: "archived";
|
|
20
|
+
}>>;
|
|
21
|
+
lastSyncedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
22
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export declare const updateExternalRefSchema: z.ZodObject<{
|
|
25
|
+
entityType: z.ZodOptional<z.ZodString>;
|
|
26
|
+
entityId: z.ZodOptional<z.ZodString>;
|
|
27
|
+
sourceSystem: z.ZodOptional<z.ZodString>;
|
|
28
|
+
objectType: z.ZodOptional<z.ZodString>;
|
|
29
|
+
namespace: z.ZodOptional<z.ZodDefault<z.ZodString>>;
|
|
30
|
+
externalId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
externalParentId: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
32
|
+
isPrimary: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
|
|
33
|
+
status: z.ZodOptional<z.ZodDefault<z.ZodEnum<{
|
|
34
|
+
active: "active";
|
|
35
|
+
inactive: "inactive";
|
|
36
|
+
archived: "archived";
|
|
37
|
+
}>>>;
|
|
38
|
+
lastSyncedAt: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
39
|
+
metadata: z.ZodOptional<z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
export declare const insertExternalRefForEntitySchema: z.ZodObject<{
|
|
42
|
+
sourceSystem: z.ZodString;
|
|
43
|
+
objectType: z.ZodString;
|
|
44
|
+
namespace: z.ZodDefault<z.ZodString>;
|
|
45
|
+
externalId: z.ZodString;
|
|
46
|
+
externalParentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
47
|
+
isPrimary: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
49
|
+
active: "active";
|
|
50
|
+
inactive: "inactive";
|
|
51
|
+
archived: "archived";
|
|
52
|
+
}>>;
|
|
53
|
+
lastSyncedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export declare const externalRefListQuerySchema: z.ZodObject<{
|
|
57
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
58
|
+
offset: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
59
|
+
entityType: z.ZodOptional<z.ZodString>;
|
|
60
|
+
entityId: z.ZodOptional<z.ZodString>;
|
|
61
|
+
sourceSystem: z.ZodOptional<z.ZodString>;
|
|
62
|
+
objectType: z.ZodOptional<z.ZodString>;
|
|
63
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
64
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
65
|
+
active: "active";
|
|
66
|
+
inactive: "inactive";
|
|
67
|
+
archived: "archived";
|
|
68
|
+
}>>;
|
|
69
|
+
search: z.ZodOptional<z.ZodString>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export declare const selectExternalRefSchema: z.ZodObject<{
|
|
72
|
+
entityType: z.ZodString;
|
|
73
|
+
entityId: z.ZodString;
|
|
74
|
+
sourceSystem: z.ZodString;
|
|
75
|
+
objectType: z.ZodString;
|
|
76
|
+
namespace: z.ZodDefault<z.ZodString>;
|
|
77
|
+
externalId: z.ZodString;
|
|
78
|
+
externalParentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
79
|
+
isPrimary: z.ZodDefault<z.ZodBoolean>;
|
|
80
|
+
status: z.ZodDefault<z.ZodEnum<{
|
|
81
|
+
active: "active";
|
|
82
|
+
inactive: "inactive";
|
|
83
|
+
archived: "archived";
|
|
84
|
+
}>>;
|
|
85
|
+
lastSyncedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
86
|
+
metadata: z.ZodOptional<z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
87
|
+
id: z.ZodString;
|
|
88
|
+
createdAt: z.ZodCoercedDate<unknown>;
|
|
89
|
+
updatedAt: z.ZodCoercedDate<unknown>;
|
|
90
|
+
}, z.core.$strip>;
|
|
91
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,uBAAuB;;;;EAA6C,CAAA;AAqBjF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;iBAAwB,CAAA;AAC5D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;iBAAkC,CAAA;AACtE,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;iBAG3C,CAAA;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;iBAQrC,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;iBAIlC,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { typeIdSchema } from "@voyantjs/db/lib/typeid";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const externalRefStatusSchema = z.enum(["active", "inactive", "archived"]);
|
|
4
|
+
const paginationSchema = z.object({
|
|
5
|
+
limit: z.coerce.number().int().min(1).max(200).default(50),
|
|
6
|
+
offset: z.coerce.number().int().min(0).default(0),
|
|
7
|
+
});
|
|
8
|
+
const externalRefCoreSchema = z.object({
|
|
9
|
+
entityType: z.string().min(1).max(100),
|
|
10
|
+
entityId: z.string().min(1).max(100),
|
|
11
|
+
sourceSystem: z.string().min(1).max(100),
|
|
12
|
+
objectType: z.string().min(1).max(100),
|
|
13
|
+
namespace: z.string().min(1).max(100).default("default"),
|
|
14
|
+
externalId: z.string().min(1).max(255),
|
|
15
|
+
externalParentId: z.string().max(255).nullable().optional(),
|
|
16
|
+
isPrimary: z.boolean().default(false),
|
|
17
|
+
status: externalRefStatusSchema.default("active"),
|
|
18
|
+
lastSyncedAt: z.string().nullable().optional(),
|
|
19
|
+
metadata: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
20
|
+
});
|
|
21
|
+
export const insertExternalRefSchema = externalRefCoreSchema;
|
|
22
|
+
export const updateExternalRefSchema = externalRefCoreSchema.partial();
|
|
23
|
+
export const insertExternalRefForEntitySchema = externalRefCoreSchema.omit({
|
|
24
|
+
entityType: true,
|
|
25
|
+
entityId: true,
|
|
26
|
+
});
|
|
27
|
+
export const externalRefListQuerySchema = paginationSchema.extend({
|
|
28
|
+
entityType: z.string().max(100).optional(),
|
|
29
|
+
entityId: z.string().max(100).optional(),
|
|
30
|
+
sourceSystem: z.string().max(100).optional(),
|
|
31
|
+
objectType: z.string().max(100).optional(),
|
|
32
|
+
namespace: z.string().max(100).optional(),
|
|
33
|
+
status: externalRefStatusSchema.optional(),
|
|
34
|
+
search: z.string().optional(),
|
|
35
|
+
});
|
|
36
|
+
export const selectExternalRefSchema = externalRefCoreSchema.extend({
|
|
37
|
+
id: typeIdSchema("external_refs"),
|
|
38
|
+
createdAt: z.coerce.date(),
|
|
39
|
+
updatedAt: z.coerce.date(),
|
|
40
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyantjs/external-refs",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./schema": {
|
|
12
|
+
"types": "./dist/schema.d.ts",
|
|
13
|
+
"import": "./dist/schema.js"
|
|
14
|
+
},
|
|
15
|
+
"./validation": {
|
|
16
|
+
"types": "./dist/validation.d.ts",
|
|
17
|
+
"import": "./dist/validation.js"
|
|
18
|
+
},
|
|
19
|
+
"./routes": {
|
|
20
|
+
"types": "./dist/routes.d.ts",
|
|
21
|
+
"import": "./dist/routes.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"drizzle-orm": "^0.45.2",
|
|
26
|
+
"hono": "^4.12.10",
|
|
27
|
+
"zod": "^4.3.6",
|
|
28
|
+
"@voyantjs/core": "0.1.0",
|
|
29
|
+
"@voyantjs/hono": "0.1.0",
|
|
30
|
+
"@voyantjs/db": "0.1.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^6.0.2",
|
|
34
|
+
"@voyantjs/voyant-typescript-config": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist"
|
|
38
|
+
],
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"lint": "biome check src/",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"build": "tsc -p tsconfig.json",
|
|
47
|
+
"clean": "rm -rf dist"
|
|
48
|
+
},
|
|
49
|
+
"main": "./dist/index.js",
|
|
50
|
+
"types": "./dist/index.d.ts"
|
|
51
|
+
}
|