@occultist/occultist 0.0.1
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 +21 -0
- package/README.md +144 -0
- package/dist/accept.d.ts +41 -0
- package/dist/accept.js +110 -0
- package/dist/accept.test.d.ts +1 -0
- package/dist/accept.test.js +44 -0
- package/dist/action.test.d.ts +1 -0
- package/dist/action.test.js +1 -0
- package/dist/actions/actionSets.d.ts +23 -0
- package/dist/actions/actionSets.js +49 -0
- package/dist/actions/actions.d.ts +163 -0
- package/dist/actions/actions.js +436 -0
- package/dist/actions/context.d.ts +78 -0
- package/dist/actions/context.js +112 -0
- package/dist/actions/meta.d.ts +49 -0
- package/dist/actions/meta.js +177 -0
- package/dist/actions/path.d.ts +21 -0
- package/dist/actions/path.js +83 -0
- package/dist/actions/path.test.d.ts +1 -0
- package/dist/actions/path.test.js +9 -0
- package/dist/actions/spec.d.ts +214 -0
- package/dist/actions/spec.js +1 -0
- package/dist/actions/types.d.ts +112 -0
- package/dist/actions/types.js +2 -0
- package/dist/actions/writer.d.ts +27 -0
- package/dist/actions/writer.js +140 -0
- package/dist/actions/writer.test.d.ts +1 -0
- package/dist/actions/writer.test.js +42 -0
- package/dist/auth/types.d.ts +14 -0
- package/dist/auth/types.js +1 -0
- package/dist/cache/cache.d.ts +30 -0
- package/dist/cache/cache.js +220 -0
- package/dist/cache/etag.d.ts +17 -0
- package/dist/cache/etag.js +83 -0
- package/dist/cache/etag.test.d.ts +1 -0
- package/dist/cache/etag.test.js +91 -0
- package/dist/cache/memory.d.ts +12 -0
- package/dist/cache/memory.js +36 -0
- package/dist/cache/types.d.ts +175 -0
- package/dist/cache/types.js +4 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +54 -0
- package/dist/jsonld.d.ts +43 -0
- package/dist/jsonld.js +1 -0
- package/dist/makeTypeDefs.d.ts +27 -0
- package/dist/makeTypeDefs.js +70 -0
- package/dist/merge.d.ts +61 -0
- package/dist/merge.js +1 -0
- package/dist/mod.d.ts +14 -0
- package/dist/mod.js +14 -0
- package/dist/processAction.d.ts +15 -0
- package/dist/processAction.js +512 -0
- package/dist/registry.d.ts +88 -0
- package/dist/registry.js +314 -0
- package/dist/registry.test.d.ts +1 -0
- package/dist/registry.test.js +133 -0
- package/dist/request.d.ts +29 -0
- package/dist/request.js +118 -0
- package/dist/scopes.d.ts +35 -0
- package/dist/scopes.js +121 -0
- package/dist/scopes.test.d.ts +1 -0
- package/dist/scopes.test.js +55 -0
- package/dist/transformers/fileTransformer.d.ts +1 -0
- package/dist/transformers/fileTransformer.js +8 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +1 -0
- package/dist/utils/alwaysArray.d.ts +1 -0
- package/dist/utils/alwaysArray.js +9 -0
- package/dist/utils/contextBuilder.d.ts +9 -0
- package/dist/utils/contextBuilder.js +82 -0
- package/dist/utils/getActionContext.d.ts +7 -0
- package/dist/utils/getActionContext.js +48 -0
- package/dist/utils/getInternalName.d.ts +6 -0
- package/dist/utils/getInternalName.js +7 -0
- package/dist/utils/getParamLocation.d.ts +2 -0
- package/dist/utils/getParamLocation.js +6 -0
- package/dist/utils/getPropertyValueSpecifications.d.ts +2 -0
- package/dist/utils/getPropertyValueSpecifications.js +49 -0
- package/dist/utils/getRequestBodyValues.d.ts +11 -0
- package/dist/utils/getRequestBodyValues.js +122 -0
- package/dist/utils/getRequestIRIValues.d.ts +14 -0
- package/dist/utils/getRequestIRIValues.js +133 -0
- package/dist/utils/isBodyInit.d.ts +1 -0
- package/dist/utils/isBodyInit.js +21 -0
- package/dist/utils/isNil.d.ts +1 -0
- package/dist/utils/isNil.js +4 -0
- package/dist/utils/isObject.d.ts +6 -0
- package/dist/utils/isObject.js +6 -0
- package/dist/utils/isPopulatedObject.d.ts +5 -0
- package/dist/utils/isPopulatedObject.js +8 -0
- package/dist/utils/isPopulatedString.d.ts +1 -0
- package/dist/utils/isPopulatedString.js +4 -0
- package/dist/utils/joinPaths.d.ts +1 -0
- package/dist/utils/joinPaths.js +31 -0
- package/dist/utils/makeAppendProblemDetails.d.ts +14 -0
- package/dist/utils/makeAppendProblemDetails.js +26 -0
- package/dist/utils/makeURLPattern.d.ts +5 -0
- package/dist/utils/makeURLPattern.js +12 -0
- package/dist/utils/normalizeURL.d.ts +4 -0
- package/dist/utils/normalizeURL.js +11 -0
- package/dist/utils/parseSearchParams.d.ts +3 -0
- package/dist/utils/parseSearchParams.js +24 -0
- package/dist/utils/preferredMediaTypes.d.ts +42 -0
- package/dist/utils/preferredMediaTypes.js +149 -0
- package/dist/utils/urlToIRI.d.ts +1 -0
- package/dist/utils/urlToIRI.js +8 -0
- package/dist/utils/validateSpecValue.d.ts +1 -0
- package/dist/utils/validateSpecValue.js +1 -0
- package/dist/validators.d.ts +16 -0
- package/dist/validators.js +134 -0
- package/lib/accept.test.ts +55 -0
- package/lib/accept.ts +147 -0
- package/lib/action.test.ts +2 -0
- package/lib/actions/actionSets.ts +88 -0
- package/lib/actions/actions.ts +795 -0
- package/lib/actions/context.ts +170 -0
- package/lib/actions/meta.ts +251 -0
- package/lib/actions/path.test.ts +15 -0
- package/lib/actions/path.ts +99 -0
- package/lib/actions/spec.ts +545 -0
- package/lib/actions/types.ts +146 -0
- package/lib/actions/writer.test.ts +57 -0
- package/lib/actions/writer.ts +176 -0
- package/lib/auth/types.ts +22 -0
- package/lib/cache/cache.ts +291 -0
- package/lib/cache/etag.test.ts +122 -0
- package/lib/cache/etag.ts +106 -0
- package/lib/cache/memory.ts +52 -0
- package/lib/cache/types.ts +240 -0
- package/lib/errors.ts +66 -0
- package/lib/jsonld.ts +67 -0
- package/lib/makeTypeDefs.ts +138 -0
- package/lib/merge.ts +86 -0
- package/lib/mod.ts +14 -0
- package/lib/processAction.ts +690 -0
- package/lib/registry.test.ts +174 -0
- package/lib/registry.ts +455 -0
- package/lib/request.ts +153 -0
- package/lib/scopes.test.ts +70 -0
- package/lib/scopes.ts +178 -0
- package/lib/transformers/fileTransformer.ts +10 -0
- package/lib/types.ts +13 -0
- package/lib/utils/alwaysArray.ts +10 -0
- package/lib/utils/contextBuilder.ts +111 -0
- package/lib/utils/getActionContext.ts +76 -0
- package/lib/utils/getInternalName.ts +15 -0
- package/lib/utils/getParamLocation.ts +14 -0
- package/lib/utils/getPropertyValueSpecifications.ts +76 -0
- package/lib/utils/getRequestBodyValues.ts +155 -0
- package/lib/utils/getRequestIRIValues.ts +201 -0
- package/lib/utils/isBodyInit.ts +22 -0
- package/lib/utils/isNil.ts +4 -0
- package/lib/utils/isObject.ts +8 -0
- package/lib/utils/isPopulatedObject.ts +9 -0
- package/lib/utils/isPopulatedString.ts +4 -0
- package/lib/utils/joinPaths.ts +36 -0
- package/lib/utils/makeAppendProblemDetails.ts +57 -0
- package/lib/utils/makeURLPattern.ts +18 -0
- package/lib/utils/normalizeURL.ts +15 -0
- package/lib/utils/parseSearchParams.ts +36 -0
- package/lib/utils/preferredMediaTypes.ts +220 -0
- package/lib/utils/urlToIRI.ts +11 -0
- package/lib/utils/validateSpecValue.ts +0 -0
- package/lib/validators.ts +186 -0
- package/package.json +41 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// Copyright 2018-2025 the Deno authors. MIT license.
|
|
2
|
+
/*!
|
|
3
|
+
* Adapted directly from negotiator at https://github.com/jshttp/negotiator/
|
|
4
|
+
* which is licensed as follows:
|
|
5
|
+
*
|
|
6
|
+
* (The MIT License)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2012-2014 Federico Romero
|
|
9
|
+
* Copyright (c) 2012-2014 Isaac Z. Schlueter
|
|
10
|
+
* Copyright (c) 2014-2015 Douglas Christopher Wilson
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
13
|
+
* a copy of this software and associated documentation files (the
|
|
14
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
15
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
16
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
17
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
18
|
+
* the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be
|
|
21
|
+
* included in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
24
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
25
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
27
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
28
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
29
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Taken from deno source as they do not export it publicly
|
|
34
|
+
* https://jsr.io/@std/http/1.0.16/_negotiation/media_type.js
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export interface Specificity {
|
|
38
|
+
i: number;
|
|
39
|
+
o: number | undefined;
|
|
40
|
+
q: number;
|
|
41
|
+
s: number | undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function compareSpecs(a: Specificity, b: Specificity): number {
|
|
45
|
+
return (
|
|
46
|
+
b.q - a.q ||
|
|
47
|
+
(b.s ?? 0) - (a.s ?? 0) ||
|
|
48
|
+
(a.o ?? 0) - (b.o ?? 0) ||
|
|
49
|
+
a.i - b.i ||
|
|
50
|
+
0
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isQuality(spec: Specificity): boolean {
|
|
55
|
+
return spec.q > 0;
|
|
56
|
+
}
|
|
57
|
+
interface MediaTypeSpecificity extends Specificity {
|
|
58
|
+
type: string;
|
|
59
|
+
subtype: string;
|
|
60
|
+
params: { [param: string]: string | undefined };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const simpleMediaTypeRegExp = /^\s*([^\s\/;]+)\/([^;\s]+)\s*(?:;(.*))?$/;
|
|
64
|
+
|
|
65
|
+
function splitKeyValuePair(str: string): [string, string | undefined] {
|
|
66
|
+
const [key, value] = str.split("=");
|
|
67
|
+
return [key!.toLowerCase(), value];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function parseMediaType(
|
|
71
|
+
str: string,
|
|
72
|
+
i: number,
|
|
73
|
+
): MediaTypeSpecificity | undefined {
|
|
74
|
+
const match = simpleMediaTypeRegExp.exec(str);
|
|
75
|
+
|
|
76
|
+
if (!match) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const [, type, subtype, parameters] = match;
|
|
81
|
+
if (!type || !subtype) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const params: { [param: string]: string | undefined } = Object.create(null);
|
|
86
|
+
let q = 1;
|
|
87
|
+
if (parameters) {
|
|
88
|
+
const kvps = parameters.split(";").map((p) => p.trim()).map(
|
|
89
|
+
splitKeyValuePair,
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
for (const [key, val] of kvps) {
|
|
93
|
+
const value = val && val[0] === `"` && val[val.length - 1] === `"`
|
|
94
|
+
? val.slice(1, val.length - 1)
|
|
95
|
+
: val;
|
|
96
|
+
|
|
97
|
+
if (key === "q" && value) {
|
|
98
|
+
q = parseFloat(value);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
params[key] = value;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return { type, subtype, params, i, o: undefined, q, s: undefined };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function parseAccept(accept: string): MediaTypeSpecificity[] {
|
|
110
|
+
const accepts = accept.split(",").map((p) => p.trim());
|
|
111
|
+
|
|
112
|
+
const mediaTypes: MediaTypeSpecificity[] = [];
|
|
113
|
+
for (const [index, accept] of accepts.entries()) {
|
|
114
|
+
const mediaType = parseMediaType(accept.trim(), index);
|
|
115
|
+
|
|
116
|
+
if (mediaType) {
|
|
117
|
+
mediaTypes.push(mediaType);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return mediaTypes;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function getFullType(spec: MediaTypeSpecificity) {
|
|
125
|
+
return `${spec.type}/${spec.subtype}`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function specify(
|
|
129
|
+
type: string,
|
|
130
|
+
spec: MediaTypeSpecificity,
|
|
131
|
+
index: number,
|
|
132
|
+
): Specificity | undefined {
|
|
133
|
+
const p = parseMediaType(type, index);
|
|
134
|
+
|
|
135
|
+
if (!p) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let s = 0;
|
|
140
|
+
|
|
141
|
+
if (spec.type.toLowerCase() === p.type.toLowerCase()) {
|
|
142
|
+
s |= 4;
|
|
143
|
+
} else if (spec.type !== "*") {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (spec.subtype.toLowerCase() === p.subtype.toLowerCase()) {
|
|
148
|
+
s |= 2;
|
|
149
|
+
} else if (spec.subtype !== "*") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const keys = Object.keys(spec.params);
|
|
154
|
+
if (keys.length) {
|
|
155
|
+
if (
|
|
156
|
+
keys.every((key) =>
|
|
157
|
+
(spec.params[key] ?? "").toLowerCase() ===
|
|
158
|
+
(p.params[key] ?? "").toLowerCase()
|
|
159
|
+
)
|
|
160
|
+
) {
|
|
161
|
+
s |= 1;
|
|
162
|
+
} else {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
i: index,
|
|
169
|
+
o: spec.o,
|
|
170
|
+
q: spec.q,
|
|
171
|
+
s,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
function getMediaTypePriority(
|
|
177
|
+
type: string,
|
|
178
|
+
accepted: MediaTypeSpecificity[],
|
|
179
|
+
index: number,
|
|
180
|
+
) {
|
|
181
|
+
let priority: Specificity = { o: -1, q: 0, s: 0, i: index };
|
|
182
|
+
|
|
183
|
+
for (const accepts of accepted) {
|
|
184
|
+
const spec = specify(type, accepts, index);
|
|
185
|
+
|
|
186
|
+
if (
|
|
187
|
+
spec &&
|
|
188
|
+
((priority.s ?? 0) - (spec.s ?? 0) ||
|
|
189
|
+
(priority.q ?? 0) - (spec.q ?? 0) ||
|
|
190
|
+
(priority.o ?? 0) - (spec.o ?? 0)) < 0
|
|
191
|
+
) {
|
|
192
|
+
priority = spec;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return priority;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function preferredMediaTypes(
|
|
200
|
+
accept?: string | null,
|
|
201
|
+
provided?: string[],
|
|
202
|
+
): string[] {
|
|
203
|
+
const accepts = parseAccept(accept === undefined ? "*/*" : accept ?? "");
|
|
204
|
+
|
|
205
|
+
if (!provided) {
|
|
206
|
+
return accepts
|
|
207
|
+
.filter(isQuality)
|
|
208
|
+
.sort(compareSpecs)
|
|
209
|
+
.map(getFullType);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const priorities = provided.map((type, index) => {
|
|
213
|
+
return getMediaTypePriority(type, accepts, index);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return priorities
|
|
217
|
+
.filter(isQuality)
|
|
218
|
+
.sort(compareSpecs)
|
|
219
|
+
.map((priority) => provided[priorities.indexOf(priority)]!);
|
|
220
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArraySpec,
|
|
3
|
+
ObjectArraySpec,
|
|
4
|
+
ObjectSpec,
|
|
5
|
+
PropertySpec,
|
|
6
|
+
} from './actions/spec.js';
|
|
7
|
+
import { isObject } from './utils/isObject.js';
|
|
8
|
+
import { preferredMediaTypes } from './utils/preferredMediaTypes.js';
|
|
9
|
+
import { JSONValue } from "./jsonld.js";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// deno-lint-ignore no-explicit-any
|
|
13
|
+
export function isFileData(value: JSONValue | File): value is string | File {
|
|
14
|
+
if (typeof value === 'string' && value.startsWith('data:')) {
|
|
15
|
+
return true;
|
|
16
|
+
} else if (value instanceof File) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isObjectArraySpec(spec: PropertySpec): spec is ObjectArraySpec {
|
|
24
|
+
return isObject(spec.properties) && Boolean(spec.multipleValues);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isObjectSpec(spec: PropertySpec): spec is ObjectSpec {
|
|
28
|
+
return isObject(spec.properties) && !spec.multipleValues;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isArraySpec(spec: PropertySpec): spec is ArraySpec {
|
|
32
|
+
return !isObject(spec.properties) && Boolean(spec.multipleValues);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function failsRequiredRequirement(
|
|
36
|
+
value: JSONValue,
|
|
37
|
+
specValue: PropertySpec,
|
|
38
|
+
) {
|
|
39
|
+
return specValue.valueRequired && (typeof value === 'undefined' || value === null);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function failsTypeRequirement(
|
|
43
|
+
value: JSONValue | File,
|
|
44
|
+
specValue: PropertySpec,
|
|
45
|
+
) {
|
|
46
|
+
const dataType = specValue.dataType;
|
|
47
|
+
|
|
48
|
+
if (dataType == null) {
|
|
49
|
+
return false;
|
|
50
|
+
} else if (specValue.dataType === 'file' && isFileData(value)) {
|
|
51
|
+
return false;
|
|
52
|
+
} else if (Array.isArray(value)) {
|
|
53
|
+
for (let index = 0; index < value.length; index++) {
|
|
54
|
+
const item = value[index];
|
|
55
|
+
|
|
56
|
+
// deno-lint-ignore valid-typeof
|
|
57
|
+
if (typeof item !== dataType) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// deno-lint-ignore valid-typeof
|
|
66
|
+
return typeof value !== specValue.dataType;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
export function failsContentTypeRequirement(
|
|
71
|
+
value: JSONValue | File,
|
|
72
|
+
specValue: PropertySpec
|
|
73
|
+
) {
|
|
74
|
+
if (
|
|
75
|
+
specValue.type !== 'file' ||
|
|
76
|
+
specValue.contentType == null ||
|
|
77
|
+
!isFileData(value)
|
|
78
|
+
) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let contentType: string | null;
|
|
83
|
+
|
|
84
|
+
if (typeof value === 'string') {
|
|
85
|
+
contentType = value.replace(/^data\:/, '').split(';')[0];
|
|
86
|
+
} else {
|
|
87
|
+
contentType = value.type;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (contentType == null) {
|
|
91
|
+
return true;
|
|
92
|
+
} else if (typeof specValue.contentType === 'string') {
|
|
93
|
+
return !preferredMediaTypes(contentType, [specValue.contentType]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return !preferredMediaTypes(contentType, specValue.contentType);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function failsMinValue(value: JSONValue, specValue: PropertySpec) {
|
|
100
|
+
if (!specValue.valueRequired && value == null) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof specValue.minValue !== 'number') {
|
|
105
|
+
return false;
|
|
106
|
+
} else if (typeof value !== 'number') {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return value < specValue.minValue;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function failsMaxValue(value: JSONValue, specValue: PropertySpec) {
|
|
114
|
+
if (!specValue.valueRequired && value == null) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (typeof specValue.maxValue !== 'number') {
|
|
119
|
+
return false;
|
|
120
|
+
} else if (typeof value !== 'number') {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return value > specValue.maxValue;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function failsStepValue(value: JSONValue, specValue: PropertySpec) {
|
|
128
|
+
if (typeof specValue.stepValue !== 'number') {
|
|
129
|
+
return false;
|
|
130
|
+
} else if (typeof value !== 'number') {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return value % specValue.stepValue !== 0;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function failsPatternValue(value: JSONValue, specValue: PropertySpec) {
|
|
138
|
+
if (typeof specValue.valuePattern !== 'string') {
|
|
139
|
+
return false;
|
|
140
|
+
} else if (typeof value !== 'string') {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const regexp = new RegExp(specValue.valuePattern);
|
|
145
|
+
|
|
146
|
+
return !regexp.test(value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function failValueMinLength(value: JSONValue, specValue: PropertySpec) {
|
|
150
|
+
if (typeof specValue.valueMinLength !== 'number') {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (typeof value === 'string' || Array.isArray(value)) {
|
|
155
|
+
return value.length < specValue.valueMinLength;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function failValueMaxLength(value: JSONValue, specValue: PropertySpec) {
|
|
162
|
+
if (typeof specValue.valueMaxLength !== 'number') {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (typeof value === 'string' || Array.isArray(value)) {
|
|
167
|
+
return value.length > specValue.valueMaxLength;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function failsValidator(
|
|
174
|
+
value: JSONValue | File,
|
|
175
|
+
specValue: PropertySpec,
|
|
176
|
+
) {
|
|
177
|
+
if (typeof specValue.validator !== 'function') {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const validator = specValue.validator as (
|
|
182
|
+
value: JSONValue | File,
|
|
183
|
+
) => boolean;
|
|
184
|
+
|
|
185
|
+
return !validator(value);
|
|
186
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@occultist/occultist",
|
|
3
|
+
"description": "A koa inspired web framework with first class support for request caching and content negotiation",
|
|
4
|
+
"author": "Matthew Quinn",
|
|
5
|
+
"homepage": "https://github.com/occultist-dev/occultist",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/occultist.ts",
|
|
9
|
+
"types": "dist/occultist.d.ts",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/occultist-dev/occultist.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/occultist-dev/occultist/issues"
|
|
16
|
+
},
|
|
17
|
+
"directories": {
|
|
18
|
+
"lib": "lib"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"./README.md",
|
|
22
|
+
"./LICENCE",
|
|
23
|
+
"./dist",
|
|
24
|
+
"./lib"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"json-ptr": "^3.1.1",
|
|
28
|
+
"jsonld": "^9.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^24.10.1",
|
|
32
|
+
"esbuild": "^0.27.0",
|
|
33
|
+
"json-ptr": "^3.1.1",
|
|
34
|
+
"jsonld": "^9.0.0",
|
|
35
|
+
"typescript": "^5.9.3"
|
|
36
|
+
},
|
|
37
|
+
"version": "0.0.1",
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc"
|
|
40
|
+
}
|
|
41
|
+
}
|