@liminalfunctions/framework 1.0.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/.mocharc.json +5 -0
- package/dist/F_Client_Collection_Registry.d.ts +18 -0
- package/dist/F_Client_Collection_Registry.js +36 -0
- package/dist/F_Client_Collection_Registry.js.map +1 -0
- package/dist/F_Collection.d.ts +21 -0
- package/dist/F_Collection.js +36 -0
- package/dist/F_Collection.js.map +1 -0
- package/dist/F_Collection_Registry.d.ts +11 -0
- package/dist/F_Collection_Registry.js +18 -0
- package/dist/F_Collection_Registry.js.map +1 -0
- package/dist/F_Compile.d.ts +4 -0
- package/dist/F_Compile.js +298 -0
- package/dist/F_Compile.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Open_Access.d.ts +11 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js +14 -0
- package/dist/F_Security_Models/F_SM_Open_Access.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Ownership.d.ts +12 -0
- package/dist/F_Security_Models/F_SM_Ownership.js +46 -0
- package/dist/F_Security_Models/F_SM_Ownership.js.map +1 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.d.ts +19 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js +73 -0
- package/dist/F_Security_Models/F_SM_Role_Membership.js.map +1 -0
- package/dist/F_Security_Models/F_Security_Model.d.ts +41 -0
- package/dist/F_Security_Models/F_Security_Model.js +29 -0
- package/dist/F_Security_Models/F_Security_Model.js.map +1 -0
- package/dist/code_generation/generate_client_library.d.ts +4 -0
- package/dist/code_generation/generate_client_library.js +158 -0
- package/dist/code_generation/generate_client_library.js.map +1 -0
- package/dist/code_generation/templates/.gitignore.mustache +383 -0
- package/dist/code_generation/templates/collection.mustache +106 -0
- package/dist/code_generation/templates/main.mustache +24 -0
- package/dist/code_generation/templates/package.json.mustache +18 -0
- package/dist/code_generation/templates/tsconfig.json.mustache +14 -0
- package/dist/code_generation/templates/types.mustache +4 -0
- package/dist/code_generation/templates/utils.ts.mustache +17 -0
- package/dist/code_generation/utils/tab_indent.d.ts +1 -0
- package/dist/code_generation/utils/tab_indent.js +4 -0
- package/dist/code_generation/utils/tab_indent.js.map +1 -0
- package/dist/code_generation/utils/type_from_zod.d.ts +2 -0
- package/dist/code_generation/utils/type_from_zod.js +102 -0
- package/dist/code_generation/utils/type_from_zod.js.map +1 -0
- package/dist/utils/cache.d.ts +13 -0
- package/dist/utils/cache.js +101 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/mongoose_from_zod.d.ts +13 -0
- package/dist/utils/mongoose_from_zod.js +164 -0
- package/dist/utils/mongoose_from_zod.js.map +1 -0
- package/dist/utils/pretty_print_zod.d.ts +2 -0
- package/dist/utils/pretty_print_zod.js +63 -0
- package/dist/utils/pretty_print_zod.js.map +1 -0
- package/dist/utils/query_object_to_mongodb_query.d.ts +3 -0
- package/dist/utils/query_object_to_mongodb_query.js +61 -0
- package/dist/utils/query_object_to_mongodb_query.js.map +1 -0
- package/dist/utils/query_validator_from_zod.d.ts +6 -0
- package/dist/utils/query_validator_from_zod.js +216 -0
- package/dist/utils/query_validator_from_zod.js.map +1 -0
- package/package.json +36 -0
- package/src/F_Collection.ts +50 -0
- package/src/F_Collection_Registry.ts +29 -0
- package/src/F_Compile.ts +368 -0
- package/src/F_Security_Models/F_SM_Open_Access.ts +21 -0
- package/src/F_Security_Models/F_SM_Ownership.ts +72 -0
- package/src/F_Security_Models/F_SM_Role_Membership.ts +87 -0
- package/src/F_Security_Models/F_Security_Model.ts +85 -0
- package/src/code_generation/generate_client_library.ts +197 -0
- package/src/code_generation/templates/.gitignore.mustache +383 -0
- package/src/code_generation/templates/collection.mustache +106 -0
- package/src/code_generation/templates/main.mustache +24 -0
- package/src/code_generation/templates/package.json.mustache +18 -0
- package/src/code_generation/templates/tsconfig.json.mustache +14 -0
- package/src/code_generation/templates/types.mustache +4 -0
- package/src/code_generation/templates/utils.ts.mustache +17 -0
- package/src/code_generation/utils/tab_indent.ts +3 -0
- package/src/code_generation/utils/type_from_zod.ts +140 -0
- package/src/utils/cache.ts +149 -0
- package/src/utils/mongoose_from_zod.ts +191 -0
- package/src/utils/pretty_print_zod.ts +75 -0
- package/src/utils/query_object_to_mongodb_query.ts +73 -0
- package/src/utils/query_validator_from_zod.ts +246 -0
- package/test/0_0_mongoose_from_zod.test.ts +260 -0
- package/test/0_1_query_validator_from_zod.test.ts +518 -0
- package/test/0_2_query_validator_to_mongodb_query.test.ts +365 -0
- package/test/0_3_cache.test.ts +204 -0
- package/test/1_0_basic_server.test.ts +530 -0
- package/test/1_1_security_ownership.test.ts +328 -0
- package/test/1_2_role_membership.test.ts +731 -0
- package/test/2_0_client_library_basic_type_generation.test.ts +444 -0
- package/test/2_0_client_library_query_type_generation.test.ts +352 -0
- package/test/2_1_client_library_generation.test.ts +255 -0
- package/test/tmp/dist/Brief_News_Category.d.ts +16 -0
- package/test/tmp/dist/Brief_News_Category.js +85 -0
- package/test/tmp/dist/Brief_News_Category.js.map +1 -0
- package/test/tmp/dist/Client.d.ts +19 -0
- package/test/tmp/dist/Client.js +97 -0
- package/test/tmp/dist/Client.js.map +1 -0
- package/test/tmp/dist/Institution.d.ts +18 -0
- package/test/tmp/dist/Institution.js +94 -0
- package/test/tmp/dist/Institution.js.map +1 -0
- package/test/tmp/dist/Project.d.ts +16 -0
- package/test/tmp/dist/Project.js +85 -0
- package/test/tmp/dist/Project.js.map +1 -0
- package/test/tmp/dist/index.d.ts +4 -0
- package/test/tmp/dist/index.js +14 -0
- package/test/tmp/dist/index.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category.js +2 -0
- package/test/tmp/dist/types/brief_news_category.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_post.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_post.js +2 -0
- package/test/tmp/dist/types/brief_news_category_post.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_put.d.ts +7 -0
- package/test/tmp/dist/types/brief_news_category_put.js +2 -0
- package/test/tmp/dist/types/brief_news_category_put.js.map +1 -0
- package/test/tmp/dist/types/brief_news_category_query.d.ts +26 -0
- package/test/tmp/dist/types/brief_news_category_query.js +2 -0
- package/test/tmp/dist/types/brief_news_category_query.js.map +1 -0
- package/test/tmp/dist/types/client.d.ts +5 -0
- package/test/tmp/dist/types/client.js +2 -0
- package/test/tmp/dist/types/client.js.map +1 -0
- package/test/tmp/dist/types/client_post.d.ts +5 -0
- package/test/tmp/dist/types/client_post.js +2 -0
- package/test/tmp/dist/types/client_post.js.map +1 -0
- package/test/tmp/dist/types/client_put.d.ts +5 -0
- package/test/tmp/dist/types/client_put.js +2 -0
- package/test/tmp/dist/types/client_put.js.map +1 -0
- package/test/tmp/dist/types/client_query.d.ts +18 -0
- package/test/tmp/dist/types/client_query.js +2 -0
- package/test/tmp/dist/types/client_query.js.map +1 -0
- package/test/tmp/dist/types/institution.d.ts +4 -0
- package/test/tmp/dist/types/institution.js +2 -0
- package/test/tmp/dist/types/institution.js.map +1 -0
- package/test/tmp/dist/types/institution_post.d.ts +4 -0
- package/test/tmp/dist/types/institution_post.js +2 -0
- package/test/tmp/dist/types/institution_post.js.map +1 -0
- package/test/tmp/dist/types/institution_put.d.ts +4 -0
- package/test/tmp/dist/types/institution_put.js +2 -0
- package/test/tmp/dist/types/institution_put.js.map +1 -0
- package/test/tmp/dist/types/institution_query.d.ts +14 -0
- package/test/tmp/dist/types/institution_query.js +2 -0
- package/test/tmp/dist/types/institution_query.js.map +1 -0
- package/test/tmp/dist/types/project.d.ts +7 -0
- package/test/tmp/dist/types/project.js +2 -0
- package/test/tmp/dist/types/project.js.map +1 -0
- package/test/tmp/dist/types/project_post.d.ts +7 -0
- package/test/tmp/dist/types/project_post.js +2 -0
- package/test/tmp/dist/types/project_post.js.map +1 -0
- package/test/tmp/dist/types/project_put.d.ts +7 -0
- package/test/tmp/dist/types/project_put.js +2 -0
- package/test/tmp/dist/types/project_put.js.map +1 -0
- package/test/tmp/dist/types/project_query.d.ts +27 -0
- package/test/tmp/dist/types/project_query.js +2 -0
- package/test/tmp/dist/types/project_query.js.map +1 -0
- package/test/tmp/dist/utils/utils.d.ts +11 -0
- package/test/tmp/dist/utils/utils.js +13 -0
- package/test/tmp/dist/utils/utils.js.map +1 -0
- package/test/tmp/package-lock.json +573 -0
- package/test/tmp/package.json +18 -0
- package/test/tmp/src/Brief_News_Category.ts +94 -0
- package/test/tmp/src/Client.ts +106 -0
- package/test/tmp/src/Institution.ts +103 -0
- package/test/tmp/src/Project.ts +94 -0
- package/test/tmp/src/index.ts +20 -0
- package/test/tmp/src/types/brief_news_category.ts +7 -0
- package/test/tmp/src/types/brief_news_category_post.ts +7 -0
- package/test/tmp/src/types/brief_news_category_put.ts +7 -0
- package/test/tmp/src/types/brief_news_category_query.ts +26 -0
- package/test/tmp/src/types/client.ts +5 -0
- package/test/tmp/src/types/client_post.ts +5 -0
- package/test/tmp/src/types/client_put.ts +5 -0
- package/test/tmp/src/types/client_query.ts +18 -0
- package/test/tmp/src/types/institution.ts +4 -0
- package/test/tmp/src/types/institution_post.ts +4 -0
- package/test/tmp/src/types/institution_put.ts +4 -0
- package/test/tmp/src/types/institution_query.ts +14 -0
- package/test/tmp/src/types/project.ts +7 -0
- package/test/tmp/src/types/project_post.ts +7 -0
- package/test/tmp/src/types/project_put.ts +7 -0
- package/test/tmp/src/types/project_query.ts +27 -0
- package/test/tmp/src/utils/utils.ts +17 -0
- package/test/tmp/tsconfig.json +14 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import { rimraf, rimrafSync, native, nativeSync } from 'rimraf'
|
|
4
|
+
|
|
5
|
+
import { z_mongodb_id } from '../dist/utils/mongoose_from_zod.js';
|
|
6
|
+
import { F_Collection } from '../dist/f_collection.js';
|
|
7
|
+
import { F_Collection_Registry } from '../dist/F_Collection_Registry.js'
|
|
8
|
+
import { F_SM_Open_Access } from '../dist/F_Security_Models/F_SM_Open_Access.js'
|
|
9
|
+
import { z, ZodBoolean, ZodDate, ZodNumber, ZodString } from 'zod'
|
|
10
|
+
import { generate_client_library } from '../dist/code_generation/generate_client_library.js'
|
|
11
|
+
|
|
12
|
+
import got from 'got'
|
|
13
|
+
import express, { Express, Request, Response, NextFunction } from 'express'
|
|
14
|
+
import mongoose, { mongo, Mongoose } from "mongoose";
|
|
15
|
+
import { Server } from "http";
|
|
16
|
+
import { mkdir, readFile } from "fs/promises";
|
|
17
|
+
|
|
18
|
+
const remove_whitespace = (input: string): string => input.replaceAll(/[\n\r\s]+/g, '')
|
|
19
|
+
|
|
20
|
+
describe('Client Library Generation: Basic Types', function () {
|
|
21
|
+
|
|
22
|
+
// before any tests run, set up the server and the db connection
|
|
23
|
+
before(async function() {
|
|
24
|
+
|
|
25
|
+
// wait for a moment because otherwise stuff breaks for no reason
|
|
26
|
+
await new Promise(resolve => setTimeout(resolve, 200))
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
after(async function (){
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
beforeEach(async function(){
|
|
33
|
+
this.timeout(20000);
|
|
34
|
+
mongoose.connection.modelNames().forEach(ele => mongoose.connection.deleteModel(ele));
|
|
35
|
+
|
|
36
|
+
await rimraf('./test/tmp');
|
|
37
|
+
await mkdir('./test/tmp');
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it(`should be able to generate a plain object`, async function () {
|
|
41
|
+
const validate_test_collection = z.object({});
|
|
42
|
+
|
|
43
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
44
|
+
|
|
45
|
+
let proto_registry = new F_Collection_Registry();
|
|
46
|
+
let registry = proto_registry.register(test_collection);
|
|
47
|
+
|
|
48
|
+
await generate_client_library('./test/tmp', registry);
|
|
49
|
+
|
|
50
|
+
assert.equal(
|
|
51
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
52
|
+
remove_whitespace(`export type test_collection = {}`)
|
|
53
|
+
)
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it(`should be able to generate a plain object containing a string`, async function () {
|
|
57
|
+
const validate_test_collection = z.object({
|
|
58
|
+
test: z.string(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
62
|
+
|
|
63
|
+
let proto_registry = new F_Collection_Registry();
|
|
64
|
+
let registry = proto_registry.register(test_collection);
|
|
65
|
+
|
|
66
|
+
await generate_client_library('./test/tmp', registry);
|
|
67
|
+
|
|
68
|
+
assert.equal(
|
|
69
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
70
|
+
remove_whitespace(`export type test_collection = {
|
|
71
|
+
"test": string
|
|
72
|
+
}`)
|
|
73
|
+
)
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it(`should be able to generate a plain object containing a number`, async function () {
|
|
77
|
+
const validate_test_collection = z.object({
|
|
78
|
+
test: z.number(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
82
|
+
|
|
83
|
+
let proto_registry = new F_Collection_Registry();
|
|
84
|
+
let registry = proto_registry.register(test_collection);
|
|
85
|
+
|
|
86
|
+
await generate_client_library('./test/tmp', registry);
|
|
87
|
+
|
|
88
|
+
assert.equal(
|
|
89
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
90
|
+
remove_whitespace(`export type test_collection = {
|
|
91
|
+
"test": number
|
|
92
|
+
}`)
|
|
93
|
+
)
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it(`should be able to generate a plain object containing a boolean`, async function () {
|
|
97
|
+
const validate_test_collection = z.object({
|
|
98
|
+
test: z.boolean(),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
102
|
+
|
|
103
|
+
let proto_registry = new F_Collection_Registry();
|
|
104
|
+
let registry = proto_registry.register(test_collection);
|
|
105
|
+
|
|
106
|
+
await generate_client_library('./test/tmp', registry);
|
|
107
|
+
|
|
108
|
+
assert.equal(
|
|
109
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
110
|
+
remove_whitespace(`export type test_collection = {
|
|
111
|
+
"test": boolean
|
|
112
|
+
}`)
|
|
113
|
+
)
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it(`should be able to generate a plain object containing a date`, async function () {
|
|
117
|
+
const validate_test_collection = z.object({
|
|
118
|
+
test: z.date(),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
122
|
+
|
|
123
|
+
let proto_registry = new F_Collection_Registry();
|
|
124
|
+
let registry = proto_registry.register(test_collection);
|
|
125
|
+
|
|
126
|
+
await generate_client_library('./test/tmp', registry);
|
|
127
|
+
|
|
128
|
+
assert.equal(
|
|
129
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
130
|
+
remove_whitespace(`export type test_collection = {
|
|
131
|
+
"test": Date
|
|
132
|
+
}`)
|
|
133
|
+
)
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it(`should be able to generate a plain object containing an objectID`, async function () {
|
|
137
|
+
const validate_test_collection = z.object({
|
|
138
|
+
test: z_mongodb_id,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
142
|
+
|
|
143
|
+
let proto_registry = new F_Collection_Registry();
|
|
144
|
+
let registry = proto_registry.register(test_collection);
|
|
145
|
+
|
|
146
|
+
await generate_client_library('./test/tmp', registry);
|
|
147
|
+
|
|
148
|
+
assert.equal(
|
|
149
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
150
|
+
remove_whitespace(`export type test_collection = {
|
|
151
|
+
"test": string
|
|
152
|
+
}`)
|
|
153
|
+
)
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it(`should be able to generate an enum`, async function () {
|
|
157
|
+
const validate_test_collection = z.object({
|
|
158
|
+
test: z.enum(["red", "green", "blue"]),
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
162
|
+
|
|
163
|
+
let proto_registry = new F_Collection_Registry();
|
|
164
|
+
let registry = proto_registry.register(test_collection);
|
|
165
|
+
|
|
166
|
+
await generate_client_library('./test/tmp', registry);
|
|
167
|
+
|
|
168
|
+
assert.equal(
|
|
169
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
170
|
+
remove_whitespace(`export type test_collection = {
|
|
171
|
+
"test": ("red" | "green" | "blue")
|
|
172
|
+
}`)
|
|
173
|
+
)
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it(`should be able to generate an array of enum`, async function () {
|
|
177
|
+
const validate_test_collection = z.object({
|
|
178
|
+
test: z.array(z.enum(["red", "green", "blue"])),
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
182
|
+
|
|
183
|
+
let proto_registry = new F_Collection_Registry();
|
|
184
|
+
let registry = proto_registry.register(test_collection);
|
|
185
|
+
|
|
186
|
+
await generate_client_library('./test/tmp', registry);
|
|
187
|
+
|
|
188
|
+
assert.equal(
|
|
189
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
190
|
+
remove_whitespace(`export type test_collection = {
|
|
191
|
+
"test": ("red" | "green" | "blue")[]
|
|
192
|
+
}`)
|
|
193
|
+
)
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it(`should be able to generate a plain nested object`, async function () {
|
|
197
|
+
const validate_test_collection = z.object({
|
|
198
|
+
test: z.object({
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
203
|
+
|
|
204
|
+
let proto_registry = new F_Collection_Registry();
|
|
205
|
+
let registry = proto_registry.register(test_collection);
|
|
206
|
+
|
|
207
|
+
await generate_client_library('./test/tmp', registry);
|
|
208
|
+
|
|
209
|
+
assert.equal(
|
|
210
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
211
|
+
remove_whitespace(`export type test_collection = {
|
|
212
|
+
"test": {}
|
|
213
|
+
}`)
|
|
214
|
+
)
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it(`should be able to generate a plain nested with basic fields`, async function () {
|
|
218
|
+
const validate_test_collection = z.object({
|
|
219
|
+
test: z.object({
|
|
220
|
+
field_string: z.string(),
|
|
221
|
+
field_number: z.number(),
|
|
222
|
+
field_boolean: z.boolean(),
|
|
223
|
+
field_date: z.date(),
|
|
224
|
+
test_2: z.object({
|
|
225
|
+
field_id: z_mongodb_id,
|
|
226
|
+
})
|
|
227
|
+
}),
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
231
|
+
|
|
232
|
+
let proto_registry = new F_Collection_Registry();
|
|
233
|
+
let registry = proto_registry.register(test_collection);
|
|
234
|
+
|
|
235
|
+
await generate_client_library('./test/tmp', registry);
|
|
236
|
+
|
|
237
|
+
assert.equal(
|
|
238
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
239
|
+
remove_whitespace(`export type test_collection = {
|
|
240
|
+
"test": {
|
|
241
|
+
"field_string": string
|
|
242
|
+
"field_number": number
|
|
243
|
+
"field_boolean": boolean
|
|
244
|
+
"field_date": Date
|
|
245
|
+
"test_2": {
|
|
246
|
+
"field_id": string
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}`)
|
|
250
|
+
)
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it(`should be able to generate arrays of primitive fields`, async function () {
|
|
254
|
+
const validate_test_collection = z.object({
|
|
255
|
+
field_string: z.array(z.string()),
|
|
256
|
+
field_number: z.array(z.number()),
|
|
257
|
+
field_boolean: z.array(z.boolean()),
|
|
258
|
+
field_date: z.array(z.date()),
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
262
|
+
|
|
263
|
+
let proto_registry = new F_Collection_Registry();
|
|
264
|
+
let registry = proto_registry.register(test_collection);
|
|
265
|
+
|
|
266
|
+
await generate_client_library('./test/tmp', registry);
|
|
267
|
+
|
|
268
|
+
assert.equal(
|
|
269
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
270
|
+
remove_whitespace(`export type test_collection = {
|
|
271
|
+
"field_string": string[]
|
|
272
|
+
"field_number": number[]
|
|
273
|
+
"field_boolean": boolean[]
|
|
274
|
+
"field_date": Date[]
|
|
275
|
+
}`)
|
|
276
|
+
)
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it(`should be able to generate arrays of objects containing primitive fields`, async function () {
|
|
280
|
+
const validate_test_collection = z.object({
|
|
281
|
+
field_array: z.array(z.object({
|
|
282
|
+
field_string: z.array(z.string()),
|
|
283
|
+
field_number: z.array(z.number()),
|
|
284
|
+
field_boolean: z.array(z.boolean()),
|
|
285
|
+
field_date: z.array(z.date()),
|
|
286
|
+
})),
|
|
287
|
+
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
291
|
+
|
|
292
|
+
let proto_registry = new F_Collection_Registry();
|
|
293
|
+
let registry = proto_registry.register(test_collection);
|
|
294
|
+
|
|
295
|
+
await generate_client_library('./test/tmp', registry);
|
|
296
|
+
|
|
297
|
+
assert.equal(
|
|
298
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
299
|
+
remove_whitespace(`export type test_collection = {
|
|
300
|
+
"field_array": {
|
|
301
|
+
"field_string": string[]
|
|
302
|
+
"field_number": number[]
|
|
303
|
+
"field_boolean": boolean[]
|
|
304
|
+
"field_date": Date[]
|
|
305
|
+
}[]
|
|
306
|
+
}`)
|
|
307
|
+
)
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it(`should be able to generate nested arrays`, async function () {
|
|
311
|
+
const validate_test_collection = z.object({
|
|
312
|
+
field_array: z.array(
|
|
313
|
+
z.array(z.object({
|
|
314
|
+
field_string: z.array(z.string()),
|
|
315
|
+
field_number: z.array(z.number()),
|
|
316
|
+
field_boolean: z.array(z.boolean()),
|
|
317
|
+
field_date: z.array(z.date()),
|
|
318
|
+
})
|
|
319
|
+
)),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
323
|
+
|
|
324
|
+
let proto_registry = new F_Collection_Registry();
|
|
325
|
+
let registry = proto_registry.register(test_collection);
|
|
326
|
+
|
|
327
|
+
await generate_client_library('./test/tmp', registry);
|
|
328
|
+
|
|
329
|
+
assert.equal(
|
|
330
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
331
|
+
remove_whitespace(`export type test_collection = {
|
|
332
|
+
"field_array": {
|
|
333
|
+
"field_string": string[]
|
|
334
|
+
"field_number": number[]
|
|
335
|
+
"field_boolean": boolean[]
|
|
336
|
+
"field_date": Date[]
|
|
337
|
+
}[][]
|
|
338
|
+
}`)
|
|
339
|
+
)
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it(`should be able to generate a plain object containing a primitive with a default`, async function () {
|
|
343
|
+
const validate_test_collection = z.object({
|
|
344
|
+
test: z.string().default('ezikiel snograss'),
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
348
|
+
|
|
349
|
+
let proto_registry = new F_Collection_Registry();
|
|
350
|
+
let registry = proto_registry.register(test_collection);
|
|
351
|
+
|
|
352
|
+
await generate_client_library('./test/tmp', registry);
|
|
353
|
+
|
|
354
|
+
assert.equal(
|
|
355
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
356
|
+
remove_whitespace(`export type test_collection = {
|
|
357
|
+
"test"?: string
|
|
358
|
+
}`)
|
|
359
|
+
)
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it(`should be able to generate a plain object containing an optional primitive`, async function () {
|
|
363
|
+
const validate_test_collection = z.object({
|
|
364
|
+
test: z.string().optional(),
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
368
|
+
|
|
369
|
+
let proto_registry = new F_Collection_Registry();
|
|
370
|
+
let registry = proto_registry.register(test_collection);
|
|
371
|
+
|
|
372
|
+
await generate_client_library('./test/tmp', registry);
|
|
373
|
+
|
|
374
|
+
assert.equal(
|
|
375
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
376
|
+
remove_whitespace(`export type test_collection = {
|
|
377
|
+
"test"?: string
|
|
378
|
+
}`)
|
|
379
|
+
)
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it(`should be able to generate a plain object containing a map`, async function () {
|
|
383
|
+
const validate_test_collection = z.object({
|
|
384
|
+
test: z.map(z.string(), z.string())
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
388
|
+
|
|
389
|
+
let proto_registry = new F_Collection_Registry();
|
|
390
|
+
let registry = proto_registry.register(test_collection);
|
|
391
|
+
|
|
392
|
+
await generate_client_library('./test/tmp', registry);
|
|
393
|
+
|
|
394
|
+
assert.equal(
|
|
395
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
396
|
+
remove_whitespace(`export type test_collection = {
|
|
397
|
+
"test": {[key: string]: string}
|
|
398
|
+
}`)
|
|
399
|
+
)
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
it(`should be able to generate a plain object containing an object map`, async function () {
|
|
404
|
+
const validate_test_collection = z.object({
|
|
405
|
+
test: z.map(z.string(), z.object({
|
|
406
|
+
test_2: z.string()
|
|
407
|
+
}))
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
411
|
+
|
|
412
|
+
let proto_registry = new F_Collection_Registry();
|
|
413
|
+
let registry = proto_registry.register(test_collection);
|
|
414
|
+
|
|
415
|
+
await generate_client_library('./test/tmp', registry);
|
|
416
|
+
|
|
417
|
+
assert.equal(
|
|
418
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
419
|
+
remove_whitespace(`export type test_collection = {
|
|
420
|
+
"test": {[key: string]: { "test_2": string }}
|
|
421
|
+
}`)
|
|
422
|
+
)
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it(`should be able to generate a plain object containing an array map`, async function () {
|
|
426
|
+
const validate_test_collection = z.object({
|
|
427
|
+
test: z.map(z.string(), z.array(z.string()))
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
let test_collection = new F_Collection('test_collection', validate_test_collection);
|
|
431
|
+
|
|
432
|
+
let proto_registry = new F_Collection_Registry();
|
|
433
|
+
let registry = proto_registry.register(test_collection);
|
|
434
|
+
|
|
435
|
+
await generate_client_library('./test/tmp', registry);
|
|
436
|
+
|
|
437
|
+
assert.equal(
|
|
438
|
+
remove_whitespace(await readFile('./test/tmp/src/types/test_collection.ts', { encoding: 'utf-8' })),
|
|
439
|
+
remove_whitespace(`export type test_collection = {
|
|
440
|
+
"test": {[key: string]: string[]}
|
|
441
|
+
}`)
|
|
442
|
+
)
|
|
443
|
+
});
|
|
444
|
+
});
|