@servable/tools 2.2.0 → 2.3.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/package.json +1 -1
- package/src/domain/protocolLoader/base.js +4 -1
- package/src/domain/protocolLoader/v1.0.0.js +11 -0
- package/src/domain/protocolLoader/v1.1.0.js +11 -0
- package/src/index.js +2 -0
- package/src/manifest/access/index.js +5 -2
- package/src/manifest/extract/formatFile.js +65 -5
- package/src/manifest/extract/index.js +14 -2
- package/src/manifest/extract/route/index.js +5 -2
- package/src/schema/artifact/index.js +15 -1
- package/src/schema/build/buildProtocol/classStruct/protocolInClassClassSchema.js +9 -0
- package/src/schema/ensuredIndexes.js +81 -0
- package/src/schema/plan/index.js +21 -0
- package/types/domain/protocolLoader/v1.0.0.d.ts +1 -0
- package/types/domain/protocolLoader/v1.1.0.d.ts +1 -0
- package/types/index.d.ts +2 -1
- package/types/manifest/access/index.d.ts +2 -1
- package/types/manifest/extract/formatFile.d.ts +4 -2
- package/types/manifest/extract/index.d.ts +5 -4
- package/types/schema/ensuredIndexes.d.ts +5 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"source": "src/index.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
7
|
-
"version": "2.
|
|
7
|
+
"version": "2.3.1",
|
|
8
8
|
"description": "Servable tools is a utility that builds a protocol's manifest and documents it.",
|
|
9
9
|
"author": "Servable Community",
|
|
10
10
|
"license": "ISC",
|
|
@@ -48,9 +48,12 @@ export default class ProtocolLoader {
|
|
|
48
48
|
*/
|
|
49
49
|
async loadExtraction({ servableConfig } = {}) {
|
|
50
50
|
try {
|
|
51
|
+
// The runtime reads a protocol's modules, never its files' JSDoc comments: those are read only to document it
|
|
52
|
+
// (`documentProtocol`, `generateGithubReadme`), which extracts the protocol again by its path, comments included.
|
|
51
53
|
this.extraction = await extract({
|
|
52
54
|
path: `${sanitizePath(this.path)}`,
|
|
53
|
-
dataTemplateType: DataTemplateType.Protocol
|
|
55
|
+
dataTemplateType: DataTemplateType.Protocol,
|
|
56
|
+
shouldReadComments: false
|
|
54
57
|
})
|
|
55
58
|
// const e = JSON.stringify(this.extraction)
|
|
56
59
|
// console.log(this.extraction)
|
|
@@ -525,6 +525,17 @@ export default class ProtocolLoaderV1_0_0 extends BaseClass {
|
|
|
525
525
|
return null
|
|
526
526
|
}
|
|
527
527
|
|
|
528
|
+
// The indexes an engine makes itself, after boot (`ensuredIndexes`: unique, partial, on a dotted path...), that
|
|
529
|
+
// this protocol gives every class it is attached to. Its own classes declare theirs in `managed.classes[]`.
|
|
530
|
+
// See schema/ensuredIndexes.js.
|
|
531
|
+
async schemaEnsuredIndexes(props) {
|
|
532
|
+
const schema = await this.schemaRaw(props)
|
|
533
|
+
if (schema && schema.target) {
|
|
534
|
+
return schema.target.ensuredIndexes
|
|
535
|
+
}
|
|
536
|
+
return null
|
|
537
|
+
}
|
|
538
|
+
|
|
528
539
|
async schemaRaw(props = {}) {
|
|
529
540
|
// Memoized for the same reason v1.1.0.js's does - schemaFields()/schemaIndexes()/
|
|
530
541
|
// schemaClassLevelPermissions() each call this independently for every protocol attached to
|
|
@@ -520,6 +520,17 @@ export default class ProtocolLoaderV1_1_0 extends BaseClass {
|
|
|
520
520
|
return null
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
+
// The indexes an engine makes itself, after boot (`ensuredIndexes`: unique, partial, on a dotted path...), that
|
|
524
|
+
// this protocol gives every class it is attached to. Its own classes declare theirs in `managed.classes[]`.
|
|
525
|
+
// See schema/ensuredIndexes.js.
|
|
526
|
+
async schemaEnsuredIndexes(props) {
|
|
527
|
+
const schema = await this.schemaRaw(props)
|
|
528
|
+
if (schema && schema.target) {
|
|
529
|
+
return schema.target.ensuredIndexes
|
|
530
|
+
}
|
|
531
|
+
return null
|
|
532
|
+
}
|
|
533
|
+
|
|
523
534
|
async schemaRaw(props = {}) {
|
|
524
535
|
// Memoized: schemaFields()/schemaIndexes()/schemaClassLevelPermissions() each call this
|
|
525
536
|
// independently for every protocol attached to every class, so without caching the same
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import plan from './schema/plan/index.js'
|
|
|
10
10
|
import generateSchemaTypes from './schema/types/index.js'
|
|
11
11
|
import buildProtocolResources from './schema/protocolResources/index.js'
|
|
12
12
|
import generateProtocolResourceTypes from './schema/protocolResources/generateTypes.js'
|
|
13
|
+
import ensuredIndexesProblemsOf from './schema/ensuredIndexes.js'
|
|
13
14
|
// import validateProtocol from './lib/config/validate/protocol/index.js'
|
|
14
15
|
import cleanProtocols from './lib/cleanProtocols.js'
|
|
15
16
|
|
|
@@ -36,6 +37,7 @@ export {
|
|
|
36
37
|
generateSchemaTypes,
|
|
37
38
|
buildProtocolResources,
|
|
38
39
|
generateProtocolResourceTypes,
|
|
40
|
+
ensuredIndexesProblemsOf,
|
|
39
41
|
cleanProtocols,
|
|
40
42
|
generateGithubReadme,
|
|
41
43
|
defineConfig,
|
|
@@ -22,6 +22,8 @@ import { DataTemplateType } from '../data/1.0.0/enums.js'
|
|
|
22
22
|
* single-vs-array collapsing). Defaults to `true`.
|
|
23
23
|
* @param {object} [props.extraction] - an already-extracted manifest tree, to skip
|
|
24
24
|
* re-extracting `path`.
|
|
25
|
+
* @param {boolean} [props.shouldReadComments] - when extracting `path` itself, also read
|
|
26
|
+
* each file's JSDoc comments (for the documentation). Defaults to `true`.
|
|
25
27
|
* @returns {Promise<object | null>} the manifest item's data, or `null` if not found.
|
|
26
28
|
*/
|
|
27
29
|
export default async ({
|
|
@@ -31,12 +33,13 @@ export default async ({
|
|
|
31
33
|
item,
|
|
32
34
|
type = DataTemplateType.Protocol,
|
|
33
35
|
formatData = true,
|
|
34
|
-
extraction: _extraction
|
|
36
|
+
extraction: _extraction,
|
|
37
|
+
shouldReadComments = true
|
|
35
38
|
}) => {
|
|
36
39
|
|
|
37
40
|
let extraction = _extraction
|
|
38
41
|
if (!extraction && path) {
|
|
39
|
-
extraction = await extract({ path: `${sanitizePath(path)}`, dataTemplateType: type })
|
|
42
|
+
extraction = await extract({ path: `${sanitizePath(path)}`, dataTemplateType: type, shouldReadComments })
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
if (!extraction) {
|
|
@@ -1,13 +1,70 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
1
2
|
import commentsParser from 'parse-comments'
|
|
2
3
|
import importFileAsText from "../../lib/importFileAsText.js"
|
|
3
4
|
import extractAst from './extractAst.js'
|
|
4
5
|
|
|
6
|
+
// parse-comments cannot read every JSDoc type: a generic inside a record type, such as
|
|
7
|
+
// `{{ query_params: Record<string, unknown> }}`, valid TypeScript-flavoured JSDoc that tsc reads, makes its type parser
|
|
8
|
+
// throw "TypeApplication does not have a name". Thrown from there, the error lost every comment of the file and was
|
|
9
|
+
// printed with its stack once per file and per protocol instance (118 times at one boot of backend/main, 2026-11-24).
|
|
10
|
+
// The comments are documentation only (`documentProtocol`), so a type it cannot read is left unparsed: the tag keeps
|
|
11
|
+
// its name, its description and its raw type (`rawType`), only its structured `type` is null.
|
|
12
|
+
const typeParserWithoutFallback = new commentsParser()
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} rawType
|
|
16
|
+
* @param {object} tag
|
|
17
|
+
*/
|
|
18
|
+
const typeOrNullWhenUnreadable = (rawType, tag) => {
|
|
19
|
+
try {
|
|
20
|
+
return typeParserWithoutFallback.parseType(rawType, tag)
|
|
21
|
+
} catch {
|
|
22
|
+
return null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parsingOptions = { parse: { type: typeOrNullWhenUnreadable } }
|
|
27
|
+
|
|
28
|
+
// A file whose comments cannot be read at all is reported once per path, not once per protocol instance reading it.
|
|
29
|
+
const pathsAlreadyReported = new Set()
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} path
|
|
33
|
+
* @returns {Promise<{ ast: object[], astAdapted: object | null }>}
|
|
34
|
+
*/
|
|
35
|
+
const parseCommentsOfFileAt = async (path) => {
|
|
36
|
+
const text = await importFileAsText(path)
|
|
37
|
+
const ast = commentsParser.parse(text, parsingOptions)
|
|
38
|
+
return { ast, astAdapted: extractAst({ ast }) }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The comments of a file, parsed once per process and per version of the file (its path and its modification time):
|
|
42
|
+
// a lib shared by many classes, or a protocol documented by several calls, is parsed once, and again only once it
|
|
43
|
+
// changed. A file whose comments cannot be read keeps its failure too, so it is not parsed again either.
|
|
44
|
+
const commentsByFileVersion = new Map()
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} path
|
|
48
|
+
* @returns {Promise<{ ast: object[], astAdapted: object | null }>}
|
|
49
|
+
*/
|
|
50
|
+
const commentsOfFileAt = async (path) => {
|
|
51
|
+
const { mtimeMs } = await fs.promises.stat(path)
|
|
52
|
+
const fileVersion = `${path}\u0000${mtimeMs}`
|
|
53
|
+
if (!commentsByFileVersion.has(fileVersion)) {
|
|
54
|
+
commentsByFileVersion.set(fileVersion, parseCommentsOfFileAt(path))
|
|
55
|
+
}
|
|
56
|
+
return commentsByFileVersion.get(fileVersion)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Reads the comments of one file of a protocol's manifest, for its documentation only: the runtime extraction of a
|
|
61
|
+
* protocol instance never calls it (see `shouldReadComments` in `./index.js`).
|
|
62
|
+
* @param {{ file: { path: string } }} props
|
|
63
|
+
* @returns {Promise<object>} The file with its comments (`ast`, `astAdapted`), or the file alone when they cannot be read.
|
|
64
|
+
*/
|
|
5
65
|
export default async ({ file }) => {
|
|
6
66
|
try {
|
|
7
|
-
const {
|
|
8
|
-
const text = await importFileAsText(path)
|
|
9
|
-
const ast = commentsParser.parse(text)
|
|
10
|
-
const astAdapted = extractAst({ ast })
|
|
67
|
+
const { ast, astAdapted } = await commentsOfFileAt(file.path)
|
|
11
68
|
|
|
12
69
|
return {
|
|
13
70
|
...file,
|
|
@@ -15,7 +72,10 @@ export default async ({ file }) => {
|
|
|
15
72
|
astAdapted
|
|
16
73
|
}
|
|
17
74
|
} catch (e) {
|
|
18
|
-
|
|
75
|
+
if (!pathsAlreadyReported.has(file.path)) {
|
|
76
|
+
pathsAlreadyReported.add(file.path)
|
|
77
|
+
console.warn('[Servable]', 'formatFile → could not read the comments of', file.path, '→', e && e.message)
|
|
78
|
+
}
|
|
19
79
|
}
|
|
20
80
|
|
|
21
81
|
return file
|
|
@@ -3,9 +3,20 @@ import extractItem from './extractItem.js'
|
|
|
3
3
|
import { DataTemplateType } from '../data/1.0.0/enums.js'
|
|
4
4
|
import ServableClass from "../../domain/servable/index.js"
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Extracts a protocol's (or a class's) manifest tree off disk: every item of its template, with the files found for
|
|
8
|
+
* each and their modules.
|
|
9
|
+
* @param {object} props
|
|
10
|
+
* @param {string} props.path - the protocol's (or the class's) root.
|
|
11
|
+
* @param {string} [props.dataTemplateType] - the template to walk. Defaults to `DataTemplateType.Protocol`.
|
|
12
|
+
* @param {boolean} [props.shouldReadComments] - also read each file's JSDoc comments (`ast`, `astAdapted`), which only
|
|
13
|
+
* the documentation uses. Defaults to `true`; a protocol instance's runtime extraction passes `false`.
|
|
14
|
+
* @returns {Promise<{ reference: object, tree: object }>}
|
|
15
|
+
*/
|
|
6
16
|
export default async ({
|
|
7
17
|
path,
|
|
8
|
-
dataTemplateType = DataTemplateType.Protocol
|
|
18
|
+
dataTemplateType = DataTemplateType.Protocol,
|
|
19
|
+
shouldReadComments = true
|
|
9
20
|
}) => {
|
|
10
21
|
const reference = {}
|
|
11
22
|
if (!global.Servable) {
|
|
@@ -16,7 +27,8 @@ export default async ({
|
|
|
16
27
|
const tree = await extractItem({
|
|
17
28
|
item,
|
|
18
29
|
reference,
|
|
19
|
-
parentLeafPath: path
|
|
30
|
+
parentLeafPath: path,
|
|
31
|
+
shouldReadComments
|
|
20
32
|
})
|
|
21
33
|
|
|
22
34
|
return { reference, tree }
|
|
@@ -6,7 +6,7 @@ import extractFiles from './extractFiles.js'
|
|
|
6
6
|
import sanitizePath from '../../../lib/sanitize.js'
|
|
7
7
|
|
|
8
8
|
export default async (props) => {
|
|
9
|
-
const { item, route, parentLeafPath } = props
|
|
9
|
+
const { item, route, parentLeafPath, shouldReadComments = true } = props
|
|
10
10
|
const { type,
|
|
11
11
|
mimeTypes,
|
|
12
12
|
variants = [''],
|
|
@@ -91,7 +91,10 @@ export default async (props) => {
|
|
|
91
91
|
if (files && files.length) {
|
|
92
92
|
files = files.filter(a => a.module)
|
|
93
93
|
if (files.length) {
|
|
94
|
-
|
|
94
|
+
// A file's comments are documentation only: a protocol instance's runtime extraction leaves them out.
|
|
95
|
+
result.data = shouldReadComments
|
|
96
|
+
? await Promise.all(files.map(async file => formatFile({ file })))
|
|
97
|
+
: files
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
} catch (e) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import buildSchema from '../build/index.js'
|
|
12
12
|
import stableStringify from '../../lib/stableStringify.js'
|
|
13
13
|
import crypto from 'crypto'
|
|
14
|
+
import ensuredIndexesProblemsOf from '../ensuredIndexes.js'
|
|
14
15
|
|
|
15
16
|
const ARTIFACT_VERSION = 1
|
|
16
17
|
|
|
@@ -20,6 +21,7 @@ const normalizeClass = (classSchema) => {
|
|
|
20
21
|
fields = {},
|
|
21
22
|
indexes = {},
|
|
22
23
|
classLevelPermissions = {},
|
|
24
|
+
ensuredIndexes,
|
|
23
25
|
} = classSchema || {}
|
|
24
26
|
|
|
25
27
|
return {
|
|
@@ -27,6 +29,9 @@ const normalizeClass = (classSchema) => {
|
|
|
27
29
|
fields,
|
|
28
30
|
indexes,
|
|
29
31
|
classLevelPermissions,
|
|
32
|
+
// Only when the class declares some (schema/ensuredIndexes.js): an artifact, and its hash, stay exactly what they
|
|
33
|
+
// were for every class that declares none.
|
|
34
|
+
...(ensuredIndexes && Object.keys(ensuredIndexes).length ? { ensuredIndexes } : {}),
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
@@ -93,9 +98,18 @@ export const normalizeArtifact = ({ appProtocol, protocols }) => {
|
|
|
93
98
|
// drift at boot (decision #4): the server calls normalizeArtifact() on the result of its own
|
|
94
99
|
// buildSchema() run to hash "what the sources say right now," rather than calling this and
|
|
95
100
|
// re-running buildSchema() a second time.
|
|
101
|
+
//
|
|
102
|
+
// It refuses (throws) an artifact whose `ensuredIndexes` are malformed, so `servable schema build`/`plan` stop on
|
|
103
|
+
// them before a commit; the boot, which calls normalizeArtifact(), never does (the engine logs such an index and
|
|
104
|
+
// carries on without it).
|
|
96
105
|
export const compileArtifact = async ({ servableConfig }) => {
|
|
97
106
|
const result = await buildSchema({ servableConfig })
|
|
98
|
-
|
|
107
|
+
const artifact = normalizeArtifact(result)
|
|
108
|
+
const problems = ensuredIndexesProblemsOf({ classes: artifact.classes })
|
|
109
|
+
if (problems.length > 0) {
|
|
110
|
+
throw new Error(`The schema's ensuredIndexes cannot be made:\n→ ${problems.join('\n→ ')}`)
|
|
111
|
+
}
|
|
112
|
+
return artifact
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
// Content-only equality - ignores generatedAt, so re-running the build with no real schema
|
|
@@ -22,6 +22,15 @@ export default async (props) => {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// Guarded: a loader written before `ensuredIndexes` existed has no such method.
|
|
26
|
+
const _ensuredIndexes = await protocol.loader.schemaEnsuredIndexes?.()
|
|
27
|
+
if (_ensuredIndexes && Object.keys(_ensuredIndexes).length) {
|
|
28
|
+
_classSchema.ensuredIndexes = {
|
|
29
|
+
..._classSchema.ensuredIndexes,
|
|
30
|
+
..._ensuredIndexes
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
//#TODO: protocol.loader
|
|
26
35
|
const _classLevelPermissions = await protocol.loader.schemaClassLevelPermissions()
|
|
27
36
|
let __classLevelPermissions
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// `ensuredIndexes`: indexes a class needs that the engine's own schema indexes (`indexes`) cannot express, declared
|
|
2
|
+
// beside them in a schema.json and made by the engine after boot, in the background (never awaited by the boot,
|
|
3
|
+
// never dropped). Engine-agnostic: fields are named as the app names them (`objectId`, a pointer by its own name, a
|
|
4
|
+
// dotted path into an object); the engine maps them to its storage.
|
|
5
|
+
//
|
|
6
|
+
// "ensuredIndexes": {
|
|
7
|
+
// "<name in the database>": {
|
|
8
|
+
// "keys": { "<field or dotted path>": 1 | -1, ... }, required, in order
|
|
9
|
+
// "isUnique": true, optional, false by default
|
|
10
|
+
// "isSparse": false, optional, true by default (rows without the field are left out),
|
|
11
|
+
// never with a partialFilter
|
|
12
|
+
// "partialFilter": { "<field>": { "$exists": true } }, optional, only the rows matching it
|
|
13
|
+
// "fieldTypes": { "<field>": { "type": "Pointer", "targetClass": "X" } }
|
|
14
|
+
// optional, the type of a field the class does not declare
|
|
15
|
+
// }
|
|
16
|
+
// }
|
|
17
|
+
//
|
|
18
|
+
// A protocol declares them on its own classes (`managed.classes[].ensuredIndexes`) or on every class it is attached
|
|
19
|
+
// to (`target.ensuredIndexes`), exactly like `indexes`, so a protocol never names another's class. They ride in the
|
|
20
|
+
// compiled artifact (`servable.schema.json`), so `schema plan` shows them and the boot's drift check covers them; a
|
|
21
|
+
// class that declares none has no `ensuredIndexes` key there, so an app that uses none keeps its artifact's hash.
|
|
22
|
+
|
|
23
|
+
const INDEX_DIRECTIONS = [1, -1]
|
|
24
|
+
const KNOWN_OPTIONS = ['keys', 'isUnique', 'isSparse', 'partialFilter', 'fieldTypes']
|
|
25
|
+
|
|
26
|
+
const isPlainObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The problems of one declaration, in words; none when it is well formed.
|
|
30
|
+
* @param {any} declaration
|
|
31
|
+
* @returns {string[]}
|
|
32
|
+
*/
|
|
33
|
+
export const problemsOfAnEnsuredIndex = (declaration) => {
|
|
34
|
+
if (!isPlainObject(declaration)) {
|
|
35
|
+
return ['the declaration is not an object']
|
|
36
|
+
}
|
|
37
|
+
const problems = []
|
|
38
|
+
const { keys, isUnique, isSparse, partialFilter, fieldTypes } = declaration
|
|
39
|
+
if (!isPlainObject(keys) || Object.keys(keys).length === 0) {
|
|
40
|
+
problems.push('`keys` names no field')
|
|
41
|
+
} else {
|
|
42
|
+
Object.entries(keys)
|
|
43
|
+
.filter(([, direction]) => !INDEX_DIRECTIONS.includes(direction))
|
|
44
|
+
.forEach(([fieldName]) => problems.push(`the direction of \`${fieldName}\` is neither 1 nor -1`))
|
|
45
|
+
}
|
|
46
|
+
if (isUnique !== undefined && typeof isUnique !== 'boolean') {
|
|
47
|
+
problems.push('`isUnique` is not a boolean')
|
|
48
|
+
}
|
|
49
|
+
if (isSparse !== undefined && typeof isSparse !== 'boolean') {
|
|
50
|
+
problems.push('`isSparse` is not a boolean')
|
|
51
|
+
}
|
|
52
|
+
if (partialFilter !== undefined && !isPlainObject(partialFilter)) {
|
|
53
|
+
problems.push('`partialFilter` is not an object')
|
|
54
|
+
}
|
|
55
|
+
if (partialFilter !== undefined && isSparse === true) {
|
|
56
|
+
problems.push('an index is either sparse or partial, not both')
|
|
57
|
+
}
|
|
58
|
+
if (fieldTypes !== undefined && !isPlainObject(fieldTypes)) {
|
|
59
|
+
problems.push('`fieldTypes` is not an object')
|
|
60
|
+
}
|
|
61
|
+
Object.keys(declaration).filter((name) => !KNOWN_OPTIONS.includes(name)).forEach((name) => problems.push(`\`${name}\` is not an option of an ensured index`))
|
|
62
|
+
return problems
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Every problem of every class's `ensuredIndexes`, each naming its class and index; none when all are well formed.
|
|
67
|
+
* @param {{ classes: any[] }} props
|
|
68
|
+
* @returns {string[]}
|
|
69
|
+
*/
|
|
70
|
+
export const ensuredIndexesProblemsOf = ({ classes }) => (classes || []).flatMap((classSchema) => {
|
|
71
|
+
const { className, ensuredIndexes } = classSchema || {}
|
|
72
|
+
if (ensuredIndexes === undefined) {
|
|
73
|
+
return []
|
|
74
|
+
}
|
|
75
|
+
if (!isPlainObject(ensuredIndexes)) {
|
|
76
|
+
return [`${className}: \`ensuredIndexes\` is not an object`]
|
|
77
|
+
}
|
|
78
|
+
return Object.entries(ensuredIndexes).flatMap(([name, declaration]) => problemsOfAnEnsuredIndex(declaration).map((problem) => `${className}.${name}: ${problem}`))
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
export default ensuredIndexesProblemsOf
|
package/src/schema/plan/index.js
CHANGED
|
@@ -62,6 +62,27 @@ const diffClass = ({ before, after }) => {
|
|
|
62
62
|
}
|
|
63
63
|
})
|
|
64
64
|
|
|
65
|
+
// ensuredIndexes (schema/ensuredIndexes.js), the same way: one added is SAFE (the engine makes it after boot, in the
|
|
66
|
+
// background); one removed or changed is BREAKING. A removed one is never dropped by the engine, but a running pod
|
|
67
|
+
// may rely on its uniqueness; a changed one clashes with the index already there under its name until someone
|
|
68
|
+
// drops it on purpose.
|
|
69
|
+
const ensuredIndexNames = new Set([
|
|
70
|
+
...Object.keys(before.ensuredIndexes || {}),
|
|
71
|
+
...Object.keys(after.ensuredIndexes || {}),
|
|
72
|
+
])
|
|
73
|
+
ensuredIndexNames.forEach(indexName => {
|
|
74
|
+
const beforeIndex = before.ensuredIndexes?.[indexName]
|
|
75
|
+
const afterIndex = after.ensuredIndexes?.[indexName]
|
|
76
|
+
if (!beforeIndex && afterIndex) {
|
|
77
|
+
changes.push({ kind: 'ensuredIndexAdded', safe: true, className: before.className, indexName })
|
|
78
|
+
} else if (beforeIndex && !afterIndex) {
|
|
79
|
+
changes.push({ kind: 'ensuredIndexRemoved', safe: false, deprecated: false, className: before.className, indexName })
|
|
80
|
+
} else if (beforeIndex && afterIndex && JSON.stringify(beforeIndex) !== JSON.stringify(afterIndex)) {
|
|
81
|
+
// Order-sensitive on purpose, like `indexes` above: the order of an index's keys is part of the index.
|
|
82
|
+
changes.push({ kind: 'ensuredIndexChanged', safe: false, deprecated: false, className: before.className, indexName })
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
|
|
65
86
|
// classLevelPermissions changes are reported but always SAFE: narrowing a CLP is an access
|
|
66
87
|
// decision, not a data-integrity one - it can't produce the "old pod can't read what's there"
|
|
67
88
|
// failure mode this whole plan/apply split exists to prevent. Flagged, not gated.
|
|
@@ -46,6 +46,7 @@ export default class ProtocolLoaderV1_0_0 extends BaseClass {
|
|
|
46
46
|
classesSchemas(props: any): Promise<any>;
|
|
47
47
|
schemaFields(props: any): Promise<any>;
|
|
48
48
|
schemaIndexes(props: any): Promise<any>;
|
|
49
|
+
schemaEnsuredIndexes(props: any): Promise<any>;
|
|
49
50
|
schemaRaw(props?: {}): Promise<any>;
|
|
50
51
|
schemaClassLevelPermissions(props: any): Promise<any>;
|
|
51
52
|
ownProtocols(): Promise<any>;
|
|
@@ -47,6 +47,7 @@ export default class ProtocolLoaderV1_1_0 extends BaseClass {
|
|
|
47
47
|
classesSchemas(props: any): Promise<any>;
|
|
48
48
|
schemaFields(props: any): Promise<any>;
|
|
49
49
|
schemaIndexes(props: any): Promise<any>;
|
|
50
|
+
schemaEnsuredIndexes(props: any): Promise<any>;
|
|
50
51
|
schemaRaw(props?: {}): Promise<any>;
|
|
51
52
|
schemaClassLevelPermissions(props: any): Promise<any>;
|
|
52
53
|
ownProtocols(): Promise<any>;
|
package/types/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import plan from './schema/plan/index.js';
|
|
|
12
12
|
import generateSchemaTypes from './schema/types/index.js';
|
|
13
13
|
import buildProtocolResources from './schema/protocolResources/index.js';
|
|
14
14
|
import generateProtocolResourceTypes from './schema/protocolResources/generateTypes.js';
|
|
15
|
+
import ensuredIndexesProblemsOf from './schema/ensuredIndexes.js';
|
|
15
16
|
import cleanProtocols from './lib/cleanProtocols.js';
|
|
16
17
|
import generateGithubReadme from './document/gateway/generateGithubReadme/index.js';
|
|
17
18
|
import defineConfig from './lib/defineConfig.js';
|
|
@@ -19,4 +20,4 @@ export namespace Domain {
|
|
|
19
20
|
export { Servable };
|
|
20
21
|
}
|
|
21
22
|
import Servable from './domain/servable/index.js';
|
|
22
|
-
export { accessManifest, documentProtocol, extractProtocol, ManifestEnums, ManifestEnumsV1_1_0, buildSchema, validateSchema, compileArtifact, artifactHashOf, normalizeArtifact, plan, generateSchemaTypes, buildProtocolResources, generateProtocolResourceTypes, cleanProtocols, generateGithubReadme, defineConfig };
|
|
23
|
+
export { accessManifest, documentProtocol, extractProtocol, ManifestEnums, ManifestEnumsV1_1_0, buildSchema, validateSchema, compileArtifact, artifactHashOf, normalizeArtifact, plan, generateSchemaTypes, buildProtocolResources, generateProtocolResourceTypes, ensuredIndexesProblemsOf, cleanProtocols, generateGithubReadme, defineConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare function _default({ path, variant, mimeType, item, type, formatData, extraction: _extraction }: {
|
|
1
|
+
declare function _default({ path, variant, mimeType, item, type, formatData, extraction: _extraction, shouldReadComments }: {
|
|
2
2
|
path?: string;
|
|
3
3
|
variant?: string;
|
|
4
4
|
mimeType?: string;
|
|
@@ -6,5 +6,6 @@ declare function _default({ path, variant, mimeType, item, type, formatData, ext
|
|
|
6
6
|
type?: string;
|
|
7
7
|
formatData?: boolean;
|
|
8
8
|
extraction?: object;
|
|
9
|
+
shouldReadComments?: boolean;
|
|
9
10
|
}): Promise<object | null>;
|
|
10
11
|
export default _default;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
declare function _default({ path, dataTemplateType }: {
|
|
2
|
-
path:
|
|
1
|
+
declare function _default({ path, dataTemplateType, shouldReadComments }: {
|
|
2
|
+
path: string;
|
|
3
3
|
dataTemplateType?: string;
|
|
4
|
+
shouldReadComments?: boolean;
|
|
4
5
|
}): Promise<{
|
|
5
|
-
reference:
|
|
6
|
-
tree:
|
|
6
|
+
reference: object;
|
|
7
|
+
tree: object;
|
|
7
8
|
}>;
|
|
8
9
|
export default _default;
|