@milaboratories/pl-model-middle-layer 1.2.20 → 1.4.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.
Files changed (52) hide show
  1. package/dist/block_meta/block_components.d.ts +221 -85
  2. package/dist/block_meta/block_components.d.ts.map +1 -1
  3. package/dist/block_meta/block_description.d.ts +872 -0
  4. package/dist/block_meta/block_description.d.ts.map +1 -0
  5. package/dist/block_meta/{block_pack_id.d.ts → block_id.d.ts} +1 -1
  6. package/dist/block_meta/block_id.d.ts.map +1 -0
  7. package/dist/block_meta/block_manifest.d.ts +1246 -0
  8. package/dist/block_meta/block_manifest.d.ts.map +1 -0
  9. package/dist/block_meta/{meta.d.ts → block_meta.d.ts} +36 -102
  10. package/dist/block_meta/block_meta.d.ts.map +1 -0
  11. package/dist/block_meta/content_conversion.d.ts +9 -1
  12. package/dist/block_meta/content_conversion.d.ts.map +1 -1
  13. package/dist/block_meta/content_types.d.ts +40 -5
  14. package/dist/block_meta/content_types.d.ts.map +1 -1
  15. package/dist/block_meta/index.d.ts +6 -1665
  16. package/dist/block_meta/index.d.ts.map +1 -1
  17. package/dist/block_registry/block_pack_spec.d.ts +201 -0
  18. package/dist/block_registry/block_pack_spec.d.ts.map +1 -0
  19. package/dist/block_registry/index.d.ts +4 -0
  20. package/dist/block_registry/index.d.ts.map +1 -0
  21. package/dist/block_registry/overview.d.ts +914 -0
  22. package/dist/block_registry/overview.d.ts.map +1 -0
  23. package/dist/block_registry/registry_spec.d.ts +184 -0
  24. package/dist/block_registry/registry_spec.d.ts.map +1 -0
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +202 -125
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/project_overview.d.ts +1 -1
  32. package/dist/project_overview.d.ts.map +1 -1
  33. package/package.json +2 -2
  34. package/src/block_meta/block_components.ts +5 -5
  35. package/src/block_meta/block_description.ts +29 -0
  36. package/src/block_meta/block_manifest.ts +40 -0
  37. package/src/block_meta/{meta.ts → block_meta.ts} +8 -13
  38. package/src/block_meta/content_conversion.ts +24 -4
  39. package/src/block_meta/content_types.ts +14 -3
  40. package/src/block_meta/index.ts +6 -52
  41. package/src/block_registry/block_pack_spec.ts +51 -0
  42. package/src/block_registry/index.ts +3 -0
  43. package/src/block_registry/overview.ts +27 -0
  44. package/src/block_registry/registry_spec.ts +38 -0
  45. package/src/index.ts +1 -1
  46. package/src/project_overview.ts +1 -1
  47. package/dist/block_meta/block_pack_id.d.ts.map +0 -1
  48. package/dist/block_meta/meta.d.ts.map +0 -1
  49. package/dist/block_pack.d.ts +0 -24
  50. package/dist/block_pack.d.ts.map +0 -1
  51. package/src/block_pack.ts +0 -29
  52. /package/src/block_meta/{block_pack_id.ts → block_id.ts} +0 -0
@@ -1,12 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import {
3
- ContentAbsoluteBinaryLocal,
4
- ContentAbsoluteTextLocal,
5
3
  ContentExplicitBase64,
6
- ContentExplicitString,
7
- ContentRelative,
8
- ContentRelativeBinary,
9
- ContentRelativeText,
4
+ ContentExplicitBytes,
10
5
  DescriptionContentBinary,
11
6
  DescriptionContentText
12
7
  } from './content_types';
@@ -40,15 +35,15 @@ export const BlockPackMetaDescriptionRaw = BlockPackMeta(
40
35
  export type BlockPackMetaDescriptionRaw = z.infer<typeof BlockPackMetaDescriptionRaw>;
41
36
 
42
37
  // prettier-ignore
43
- export const BlockPackMetaManifest = BlockPackMeta(
44
- ContentRelativeText,
45
- ContentRelativeBinary
38
+ export const BlockPackMetaEmbeddedBase64 = BlockPackMeta(
39
+ z.string(),
40
+ ContentExplicitBase64
46
41
  );
47
- export type BlockPackMetaManifest = z.infer<typeof BlockPackMetaManifest>;
42
+ export type BlockPackMetaEmbeddedBase64 = z.infer<typeof BlockPackMetaEmbeddedBase64>;
48
43
 
49
44
  // prettier-ignore
50
- export const BlockPackMetaEmbeddedContent = BlockPackMeta(
45
+ export const BlockPackMetaEmbeddedBytes = BlockPackMeta(
51
46
  z.string(),
52
- ContentExplicitBase64
47
+ ContentExplicitBytes
53
48
  );
54
- export type BlockPackMetaEmbeddedContent = z.infer<typeof BlockPackMetaEmbeddedContent>;
49
+ export type BlockPackMetaEmbeddedBytes = z.infer<typeof BlockPackMetaEmbeddedBytes>;
@@ -1,13 +1,33 @@
1
- import { ContentAbsoluteUrl, ContentAnyLocal, ContentRelative } from "./content_types";
1
+ import {
2
+ ContentAbsoluteUrl,
3
+ ContentAnyLocal,
4
+ ContentExplicitOrRelative,
5
+ ContentRelative
6
+ } from './content_types';
2
7
 
3
8
  export function mapRemoteToAbsolute(
4
9
  rootUrl: string
5
- ): <T extends ContentAnyLocal>(
6
- value: T
7
- ) => Exclude<T, ContentRelative> | ContentAbsoluteUrl {
10
+ ): <T extends ContentAnyLocal>(value: T) => Exclude<T, ContentRelative> | ContentAbsoluteUrl {
8
11
  const rootWithSlash = rootUrl.endsWith('/') ? rootUrl : `${rootUrl}/`;
9
12
  return <T extends ContentAnyLocal>(value: T) =>
10
13
  value.type === 'relative'
11
14
  ? { type: 'absolute-url', url: rootWithSlash + value.path }
12
15
  : (value as Exclude<T, ContentRelative>);
13
16
  }
17
+
18
+ /**
19
+ * Creates transformer of relative content paths, that adds a specific prefix to the relative path.
20
+ *
21
+ * If prefix = "nested-path/", paths like "somefile.txt" will be transformed to "nested-path/somefile.txt".
22
+ *
23
+ * @param prefix prefix to add to the relaive path, slesh at the end will be added automatically if missed
24
+ */
25
+ export function addPrefixToRelative(
26
+ prefix: string
27
+ ): <T extends ContentExplicitOrRelative>(value: T) => T {
28
+ const prefixWithSlash = prefix.endsWith('/') ? prefix : `${prefix}/`;
29
+ return <T extends ContentExplicitOrRelative>(value: T) =>
30
+ (value.type === 'relative'
31
+ ? { type: 'relative', path: prefixWithSlash + value.path }
32
+ : value) as T;
33
+ }
@@ -56,13 +56,17 @@ export type ContentAbsoluteUrl = z.infer<typeof ContentAbsoluteUrl>;
56
56
  // Special content types
57
57
  //
58
58
 
59
- export const ContentExplicit = z
59
+ export const ContentExplicitBytes = z
60
60
  .object({
61
- type: z.literal('explicit'),
61
+ type: z.literal('explicit-bytes'),
62
+ mimeType: z
63
+ .string()
64
+ .regex(/\w+\/[-+.\w]+/)
65
+ .describe('MIME type to interpret content'),
62
66
  content: z.instanceof(Uint8Array).describe('Raw content')
63
67
  })
64
68
  .strict();
65
- export type ContentExplicit = z.infer<typeof ContentExplicit>;
69
+ export type ContentExplicitBytes = z.infer<typeof ContentExplicitBytes>;
66
70
 
67
71
  export const ContentAbsoluteFolder = z
68
72
  .object({
@@ -88,6 +92,13 @@ export const ContentAny = z.discriminatedUnion('type', [
88
92
  ]);
89
93
  export type ContentAny = z.infer<typeof ContentAny>;
90
94
 
95
+ export const ContentExplicitOrRelative = z.discriminatedUnion('type', [
96
+ ContentExplicitString,
97
+ ContentExplicitBase64,
98
+ ContentRelative
99
+ ]);
100
+ export type ContentExplicitOrRelative = z.infer<typeof ContentExplicitOrRelative>;
101
+
91
102
  export const ContentAnyLocal = z.discriminatedUnion('type', [
92
103
  ContentExplicitString,
93
104
  ContentExplicitBase64,
@@ -1,57 +1,11 @@
1
- import { ZodTypeAny, string, z } from 'zod';
2
- import { BlockComponentsDescriptionRaw, BlockComponentsManifest } from './block_components';
3
- import { BlockPackId } from './block_pack_id';
4
- import { BlockPackMetaDescriptionRaw, BlockPackMetaManifest } from './meta';
5
-
6
- export * from './block_components';
7
- export * from './block_pack_id';
8
1
  export * from './common';
9
2
  export * from './content_types';
10
- export * from './meta';
11
3
  export * from './semver';
12
4
 
13
- export const BlockPackDescriptionFromPackageJsonRaw = z.object({
14
- components: BlockComponentsDescriptionRaw,
15
- meta: BlockPackMetaDescriptionRaw
16
- });
17
-
18
- export function CreateBlockPackDescriptionSchema<
19
- Components extends ZodTypeAny,
20
- Meta extends ZodTypeAny
21
- >(components: Components, meta: Meta) {
22
- return z.object({
23
- id: BlockPackId,
24
- components,
25
- meta
26
- });
27
- }
28
-
29
- export const BlockPackDescriptionManifest = CreateBlockPackDescriptionSchema(
30
- BlockComponentsManifest,
31
- BlockPackMetaManifest
32
- );
33
- export type BlockPackDescriptionManifest = z.infer<typeof BlockPackDescriptionManifest>;
5
+ export * from './content_conversion';
34
6
 
35
- export const BlockPackDescriptionRaw = CreateBlockPackDescriptionSchema(
36
- BlockComponentsDescriptionRaw,
37
- BlockPackMetaDescriptionRaw
38
- );
39
- export type BlockPackDescriptionRaw = z.infer<typeof BlockPackDescriptionRaw>;
40
-
41
- export const ManifestFileInfo = z.object({
42
- name: z.string(),
43
- size: z.number().int(),
44
- sha256: z
45
- .string()
46
- .regex(/[0-9a-fA-F]/)
47
- .toUpperCase()
48
- .length(64) // 256 / 4 (bits per hex register)
49
- });
50
- export type ManifestFileInfo = z.infer<typeof ManifestFileInfo>;
51
-
52
- export const BlockPackManifest = z.object({
53
- schema: z.literal('v1'),
54
- description: BlockPackDescriptionManifest,
55
- files: z.array(ManifestFileInfo)
56
- });
57
- export type BlockPackManifest = z.infer<typeof BlockPackManifest>;
7
+ export * from './block_id';
8
+ export * from './block_components';
9
+ export * from './block_meta';
10
+ export * from './block_description';
11
+ export * from './block_manifest';
@@ -0,0 +1,51 @@
1
+ import { z } from 'zod';
2
+ import { BlockPackId } from '../block_meta';
3
+
4
+ /** Block pack from local folder, to be used during block development. Old layout.
5
+ * @deprecated don't use */
6
+ export const BlockPackDevV1 = z.object({
7
+ type: z.literal('dev-v1'),
8
+ folder: z.string(),
9
+ mtime: z.string().optional()
10
+ });
11
+ /** @deprecated don't use */
12
+ export type BlockPackDevV1 = z.infer<typeof BlockPackDevV1>;
13
+
14
+ /** Block pack from local folder, to be used during block development. New layout. */
15
+ export const BlockPackDevV2 = z.object({
16
+ type: z.literal('dev-v2'),
17
+ folder: z.string(),
18
+ mtime: z.string().optional()
19
+ });
20
+ export type BlockPackDevV2 = z.infer<typeof BlockPackDevV2>;
21
+
22
+ /**
23
+ * Block pack from registry with version 2 layout, to be loaded directly
24
+ * from the client.
25
+ * @deprecated don't use
26
+ * */
27
+ export const BlockPackFromRegistryV1 = z.object({
28
+ type: z.literal('from-registry-v1'),
29
+ registryUrl: z.string(),
30
+ id: BlockPackId
31
+ });
32
+ /** @deprecated don't use */
33
+ export type BlockPackFromRegistryV1 = z.infer<typeof BlockPackFromRegistryV1>;
34
+
35
+ /** Block pack from registry with version 2 layout, to be loaded directly
36
+ * from the client. */
37
+ export const BlockPackFromRegistryV2 = z.object({
38
+ type: z.literal('from-registry-v2'),
39
+ registryUrl: z.string(),
40
+ id: BlockPackId
41
+ });
42
+ export type BlockPackFromRegistryV2 = z.infer<typeof BlockPackFromRegistryV2>;
43
+
44
+ /** Information about block origin, can be used to instantiate new blocks */
45
+ export const BlockPackSpec = z.discriminatedUnion('type', [
46
+ BlockPackDevV1,
47
+ BlockPackDevV2,
48
+ BlockPackFromRegistryV1,
49
+ BlockPackFromRegistryV2
50
+ ]);
51
+ export type BlockPackSpec = z.infer<typeof BlockPackSpec>;
@@ -0,0 +1,3 @@
1
+ export * from './block_pack_spec';
2
+ export * from './overview';
3
+ export * from './registry_spec';
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+ import { BlockPackId, BlockPackMetaEmbeddedBytes, SemVer } from '../block_meta';
3
+ import { BlockPackSpec } from './block_pack_spec';
4
+ import { RegistryEntry } from './registry_spec';
5
+
6
+ /**
7
+ * Latest information about specific block pack. Contain information about latest version of the package.
8
+ * */
9
+ export const BlockPackOverview = z.object({
10
+ registryId: z.string(),
11
+ id: BlockPackId,
12
+ meta: BlockPackMetaEmbeddedBytes,
13
+ spec: BlockPackSpec,
14
+ otherVersions: z.array(SemVer)
15
+ });
16
+ export type BlockPackOverview = z.infer<typeof BlockPackOverview>;
17
+
18
+ export const RegistryStatus = RegistryEntry.extend({
19
+ status: z.union([z.literal('online'), z.literal('offline')])
20
+ });
21
+ export type RegistryStatus = z.infer<typeof RegistryStatus>;
22
+
23
+ export const BlockPackListing = z.object({
24
+ registries: z.array(RegistryStatus),
25
+ blockPacks: z.array(BlockPackOverview)
26
+ });
27
+ export type BlockPackListing = z.infer<typeof BlockPackListing>;
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+
3
+ export const LocalDevFolder = z.object({
4
+ type: z.literal('local-dev'),
5
+ path: z.string()
6
+ });
7
+ export type LocalDevFolder = z.infer<typeof LocalDevFolder>;
8
+
9
+ /** @deprecated don't use */
10
+ export const RemoteRegistryV1Spec = z.object({
11
+ type: z.literal('remote-v1'),
12
+ url: z.string().url()
13
+ });
14
+ /** @deprecated don't use */
15
+ export type RemoteRegistryV1Spec = z.infer<typeof RemoteRegistryV1Spec>;
16
+
17
+ export const RemoteRegistryV2Spec = z.object({
18
+ type: z.literal('remote-v2'),
19
+ url: z.string().url()
20
+ });
21
+ export type RemoteRegistryV2Spec = z.infer<typeof RemoteRegistryV2Spec>;
22
+
23
+ export const RegistrySpec = z.discriminatedUnion('type', [
24
+ RemoteRegistryV1Spec,
25
+ RemoteRegistryV2Spec,
26
+ LocalDevFolder
27
+ ]);
28
+ export type RegistrySpec = z.infer<typeof RegistrySpec>;
29
+
30
+ export const RegistryEntry = z.object({
31
+ id: z.string(),
32
+ title: z.string().optional(),
33
+ spec: RegistrySpec
34
+ });
35
+ export type RegistryEntry = z.infer<typeof RegistryEntry>;
36
+
37
+ export const RegistryList = z.array(RegistryEntry);
38
+ export type RegistryList = z.infer<typeof RegistryList>;
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './author_marker';
2
- export * from './block_pack';
2
+ export * from './block_registry';
3
3
  export * from './block_state';
4
4
  export * from './block_meta';
5
5
  export * from './project';
@@ -1,5 +1,5 @@
1
1
  import { ProjectMeta } from './project';
2
- import { BlockPackSpec } from './block_pack';
2
+ import { BlockPackSpec } from './block_registry/block_pack_spec';
3
3
  import { BlockRenderingMode, BlockSection, NavigationState } from '@milaboratories/pl-model-common';
4
4
  import { AuthorMarker } from './author_marker';
5
5
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"block_pack_id.d.ts","sourceRoot":"","sources":["../../src/block_meta/block_pack_id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,qCAAqC;AACrC,eAAO,MAAM,WAAW;;;;;;;;;;;;EAMb,CAAC;AACZ,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEtD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAAsC,CAAC;AACxE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../src/block_meta/meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,wBAAgB,aAAa,CAC3B,KAAK,CAAC,cAAc,SAAS,CAAC,CAAC,UAAU,EACzC,KAAK,CAAC,UAAU,SAAS,CAAC,CAAC,UAAU,EACrC,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgB/C;AAGD,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGvC,CAAC;AACF,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAGtF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAG1E,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGxC,CAAC;AACF,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC"}
@@ -1,24 +0,0 @@
1
- /** Block pack from local folder, to be used during block development. Legacy layout. */
2
- export interface BlockPackDevV1 {
3
- type: 'dev' | 'dev-v1';
4
- folder: string;
5
- mtime?: string;
6
- }
7
- /** Block pack from local folder, to be used during block development. New layout. */
8
- export interface BlockPackDevV2 {
9
- type: 'dev-v2';
10
- folder: string;
11
- mtime?: string;
12
- }
13
- /** Block pack from registry with version 1 layout, to be loaded directly
14
- * from the client. */
15
- export interface BlockPackFromRegistryV1 {
16
- type: 'from-registry-v1';
17
- registryUrl: string;
18
- organization: string;
19
- package: string;
20
- version: string;
21
- }
22
- /** Information about block origin, can be used to instantiate new blocks */
23
- export type BlockPackSpec = BlockPackDevV1 | BlockPackDevV2 | BlockPackFromRegistryV1;
24
- //# sourceMappingURL=block_pack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"block_pack.d.ts","sourceRoot":"","sources":["../src/block_pack.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,KAAK,GAAG,QAAQ,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qFAAqF;AACrF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;sBACsB;AACtB,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,kBAAkB,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,4EAA4E;AAC5E,MAAM,MAAM,aAAa,GACrB,cAAc,GACd,cAAc,GACd,uBAAuB,CAAC"}
package/src/block_pack.ts DELETED
@@ -1,29 +0,0 @@
1
- /** Block pack from local folder, to be used during block development. Legacy layout. */
2
- export interface BlockPackDevV1 {
3
- type: 'dev' | 'dev-v1';
4
- folder: string;
5
- mtime?: string;
6
- }
7
-
8
- /** Block pack from local folder, to be used during block development. New layout. */
9
- export interface BlockPackDevV2 {
10
- type: 'dev-v2';
11
- folder: string;
12
- mtime?: string;
13
- }
14
-
15
- /** Block pack from registry with version 1 layout, to be loaded directly
16
- * from the client. */
17
- export interface BlockPackFromRegistryV1 {
18
- type: 'from-registry-v1';
19
- registryUrl: string;
20
- organization: string;
21
- package: string;
22
- version: string;
23
- }
24
-
25
- /** Information about block origin, can be used to instantiate new blocks */
26
- export type BlockPackSpec =
27
- | BlockPackDevV1
28
- | BlockPackDevV2
29
- | BlockPackFromRegistryV1;