@player-tools/json-language-service 0.4.2--canary.69.1573 → 0.4.2-next.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/dist/index.cjs.js CHANGED
@@ -1863,48 +1863,41 @@ var __spreadValues$1 = (a, b) => {
1863
1863
  return a;
1864
1864
  };
1865
1865
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1866
- const applyCommonProps = (inputNode, capability) => {
1867
- const outputNode = __spreadValues$1({}, inputNode);
1868
- if (capability === "Assets") {
1869
- if (outputNode.type === "object") {
1870
- if (!outputNode.properties.applicability) {
1871
- outputNode.properties.applicability = {
1872
- required: false,
1873
- node: {
1874
- type: "or",
1875
- name: "Applicability",
1876
- description: "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
1877
- or: [
1878
- {
1879
- type: "boolean"
1880
- },
1881
- {
1882
- type: "ref",
1883
- ref: "Expression"
1884
- }
1885
- ]
1886
- }
1887
- };
1888
- }
1866
+ const applyCommonProps = (node, capability) => {
1867
+ return xlrSdk.simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
1868
+ if (!xlrNode.properties.applicability) {
1869
+ xlrNode.properties.applicability = {
1870
+ required: false,
1871
+ node: {
1872
+ type: "or",
1873
+ name: "Applicability",
1874
+ description: "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
1875
+ or: [
1876
+ {
1877
+ type: "boolean"
1878
+ },
1879
+ {
1880
+ type: "ref",
1881
+ ref: "Expression"
1882
+ }
1883
+ ]
1884
+ }
1885
+ };
1889
1886
  }
1890
- }
1891
- if (outputNode.type === "object" && !outputNode.properties._comment) {
1892
- outputNode.properties._comment = {
1893
- required: false,
1894
- node: {
1895
- description: "Adds a comment for the given node",
1896
- type: "string"
1897
- }
1898
- };
1899
- } else if (outputNode.type === "and") {
1900
- outputNode.and.map((n) => applyCommonProps(n, capability));
1901
- } else if (outputNode.type === "or") {
1902
- outputNode.or.map((n) => applyCommonProps(n, capability));
1903
- }
1904
- return outputNode;
1887
+ if (!xlrNode.properties._comment) {
1888
+ xlrNode.properties._comment = {
1889
+ required: false,
1890
+ node: {
1891
+ description: "Adds a comment for the given node",
1892
+ type: "string"
1893
+ }
1894
+ };
1895
+ }
1896
+ return xlrNode;
1897
+ })(node, capability);
1905
1898
  };
1906
1899
  const applyAssetWrapperOrSwitch = (node, capability) => {
1907
- return xlrSdk.simpleTransformGenerator("ref", "Assets", (xlrNode) => {
1900
+ return xlrSdk.simpleTransformGenerator("ref", ["Assets", "Views"], (xlrNode) => {
1908
1901
  if (xlrNode.ref.includes("AssetWrapper")) {
1909
1902
  return __spreadProps$1(__spreadValues$1({}, xlrNode), {
1910
1903
  ref: xlrNode.ref.replace("AssetWrapper", "AssetWrapperOrSwitch")
@@ -1953,8 +1946,8 @@ const applyValueRefs = (node, capability) => {
1953
1946
  })(node, capability);
1954
1947
  };
1955
1948
  const applyTemplateProperty = (node, capability) => {
1956
- const templateTypes = [];
1957
- return xlrSdk.simpleTransformGenerator("object", "Assets", (inputNode) => {
1949
+ return xlrSdk.simpleTransformGenerator("object", ["Assets", "Views"], (inputNode) => {
1950
+ const templateTypes = [];
1958
1951
  const xlrNode = __spreadValues$1({}, inputNode);
1959
1952
  for (const key in xlrNode.properties) {
1960
1953
  const value = xlrNode.properties[key];
@@ -2449,6 +2442,12 @@ class PlayerLanguageService {
2449
2442
  return this.hooks.definition.call(context);
2450
2443
  });
2451
2444
  }
2445
+ addXLRTransforms(transforms) {
2446
+ Object.entries(transforms).forEach(([name, fn]) => this.XLRService.XLRSDK.addTransformFunction(name, fn));
2447
+ }
2448
+ addLSPPlugin(plugin) {
2449
+ plugin.apply(this);
2450
+ }
2452
2451
  setAssetTypes(typeFiles) {
2453
2452
  return __async(this, null, function* () {
2454
2453
  typeFiles.forEach((file) => {
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { TextDocument } from 'vscode-languageserver-textdocument';
2
2
  import { SyncHook, AsyncParallelHook, SyncWaterfallHook, SyncBailHook } from 'tapable-ts';
3
3
  import { Diagnostic, Range, TextEdit, Position, DiagnosticSeverity, CompletionItem, Location, Hover, FormattingOptions, CompletionList, CodeActionContext, CodeAction } from 'vscode-languageserver-types';
4
- import { Node } from 'jsonc-parser';
5
- import { BasicXLRRegistry, Filters, TypeMetadata, XLRSDK } from '@player-tools/xlr-sdk';
6
4
  import * as _player_tools_xlr from '@player-tools/xlr';
7
5
  import { NamedType, NodeType, ObjectType, TransformFunction } from '@player-tools/xlr';
6
+ import { Node } from 'jsonc-parser';
7
+ import { BasicXLRRegistry, Filters, TypeMetadata, XLRSDK } from '@player-tools/xlr-sdk';
8
8
 
9
9
  declare type ASTNode = StringASTNode | NumberASTNode | BooleanASTNode | ArrayASTNode | NullASTNode | PropertyASTNode | ObjectASTNode | AssetASTNode | ViewASTNode | ContentASTNode | NavigationASTNode | FlowASTNode | EmptyASTNode | FlowStateASTNode;
10
10
  interface BaseASTNode<T extends string> {
@@ -443,6 +443,8 @@ declare class PlayerLanguageService {
443
443
  getHoverInfoAtPosition(document: TextDocument, position: Position): Promise<Hover | undefined | null>;
444
444
  getCodeActionsInRange(document: TextDocument, context: CodeActionContext): Promise<CodeAction[]>;
445
445
  getDefinitionAtPosition(document: TextDocument, position: Position): Promise<Location | undefined | null>;
446
+ addXLRTransforms(transforms: Record<string, TransformFunction>): void;
447
+ addLSPPlugin(plugin: PlayerLanguageServicePlugin): void;
446
448
  setAssetTypes(typeFiles: Array<string>): Promise<void>;
447
449
  }
448
450
 
package/dist/index.esm.js CHANGED
@@ -1855,48 +1855,41 @@ var __spreadValues$1 = (a, b) => {
1855
1855
  return a;
1856
1856
  };
1857
1857
  var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1858
- const applyCommonProps = (inputNode, capability) => {
1859
- const outputNode = __spreadValues$1({}, inputNode);
1860
- if (capability === "Assets") {
1861
- if (outputNode.type === "object") {
1862
- if (!outputNode.properties.applicability) {
1863
- outputNode.properties.applicability = {
1864
- required: false,
1865
- node: {
1866
- type: "or",
1867
- name: "Applicability",
1868
- description: "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
1869
- or: [
1870
- {
1871
- type: "boolean"
1872
- },
1873
- {
1874
- type: "ref",
1875
- ref: "Expression"
1876
- }
1877
- ]
1878
- }
1879
- };
1880
- }
1858
+ const applyCommonProps = (node, capability) => {
1859
+ return simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
1860
+ if (!xlrNode.properties.applicability) {
1861
+ xlrNode.properties.applicability = {
1862
+ required: false,
1863
+ node: {
1864
+ type: "or",
1865
+ name: "Applicability",
1866
+ description: "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
1867
+ or: [
1868
+ {
1869
+ type: "boolean"
1870
+ },
1871
+ {
1872
+ type: "ref",
1873
+ ref: "Expression"
1874
+ }
1875
+ ]
1876
+ }
1877
+ };
1881
1878
  }
1882
- }
1883
- if (outputNode.type === "object" && !outputNode.properties._comment) {
1884
- outputNode.properties._comment = {
1885
- required: false,
1886
- node: {
1887
- description: "Adds a comment for the given node",
1888
- type: "string"
1889
- }
1890
- };
1891
- } else if (outputNode.type === "and") {
1892
- outputNode.and.map((n) => applyCommonProps(n, capability));
1893
- } else if (outputNode.type === "or") {
1894
- outputNode.or.map((n) => applyCommonProps(n, capability));
1895
- }
1896
- return outputNode;
1879
+ if (!xlrNode.properties._comment) {
1880
+ xlrNode.properties._comment = {
1881
+ required: false,
1882
+ node: {
1883
+ description: "Adds a comment for the given node",
1884
+ type: "string"
1885
+ }
1886
+ };
1887
+ }
1888
+ return xlrNode;
1889
+ })(node, capability);
1897
1890
  };
1898
1891
  const applyAssetWrapperOrSwitch = (node, capability) => {
1899
- return simpleTransformGenerator("ref", "Assets", (xlrNode) => {
1892
+ return simpleTransformGenerator("ref", ["Assets", "Views"], (xlrNode) => {
1900
1893
  if (xlrNode.ref.includes("AssetWrapper")) {
1901
1894
  return __spreadProps$1(__spreadValues$1({}, xlrNode), {
1902
1895
  ref: xlrNode.ref.replace("AssetWrapper", "AssetWrapperOrSwitch")
@@ -1945,8 +1938,8 @@ const applyValueRefs = (node, capability) => {
1945
1938
  })(node, capability);
1946
1939
  };
1947
1940
  const applyTemplateProperty = (node, capability) => {
1948
- const templateTypes = [];
1949
- return simpleTransformGenerator("object", "Assets", (inputNode) => {
1941
+ return simpleTransformGenerator("object", ["Assets", "Views"], (inputNode) => {
1942
+ const templateTypes = [];
1950
1943
  const xlrNode = __spreadValues$1({}, inputNode);
1951
1944
  for (const key in xlrNode.properties) {
1952
1945
  const value = xlrNode.properties[key];
@@ -2441,6 +2434,12 @@ class PlayerLanguageService {
2441
2434
  return this.hooks.definition.call(context);
2442
2435
  });
2443
2436
  }
2437
+ addXLRTransforms(transforms) {
2438
+ Object.entries(transforms).forEach(([name, fn]) => this.XLRService.XLRSDK.addTransformFunction(name, fn));
2439
+ }
2440
+ addLSPPlugin(plugin) {
2441
+ plugin.apply(this);
2442
+ }
2444
2443
  setAssetTypes(typeFiles) {
2445
2444
  return __async(this, null, function* () {
2446
2445
  typeFiles.forEach((file) => {
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@player-tools/json-language-service",
3
- "version": "0.4.2--canary.69.1573",
3
+ "version": "0.4.2-next.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org"
7
7
  },
8
8
  "peerDependencies": {},
9
9
  "dependencies": {
10
- "@player-tools/xlr": "0.4.2--canary.69.1573",
11
- "@player-tools/xlr-sdk": "0.4.2--canary.69.1573",
12
- "@player-tools/xlr-utils": "0.4.2--canary.69.1573",
10
+ "@player-tools/xlr": "0.4.2-next.1",
11
+ "@player-tools/xlr-sdk": "0.4.2-next.1",
12
+ "@player-tools/xlr-utils": "0.4.2-next.1",
13
13
  "change-case": "^4.1.1",
14
14
  "cross-fetch": "^3.0.5",
15
15
  "detect-indent": "^6.0.0",
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  CodeActionKind,
28
28
  } from 'vscode-languageserver-types';
29
29
 
30
+ import type { TransformFunction } from '@player-tools/xlr';
30
31
  import type {
31
32
  DocumentContext,
32
33
  ValidationContext,
@@ -415,6 +416,16 @@ export class PlayerLanguageService {
415
416
  return this.hooks.definition.call(context);
416
417
  }
417
418
 
419
+ public addXLRTransforms(transforms: Record<string, TransformFunction>): void {
420
+ Object.entries(transforms).forEach(([name, fn]) =>
421
+ this.XLRService.XLRSDK.addTransformFunction(name, fn)
422
+ );
423
+ }
424
+
425
+ public addLSPPlugin(plugin: PlayerLanguageServicePlugin) {
426
+ plugin.apply(this);
427
+ }
428
+
418
429
  async setAssetTypes(typeFiles: Array<string>) {
419
430
  // await this.typescriptService.setAssetTypes(typeFiles);
420
431
  typeFiles.forEach((file) => {
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable guard-for-in */
2
2
  /* eslint-disable no-restricted-syntax */
3
- /* eslint-disable no-param-reassign */
3
+
4
4
  import type {
5
5
  ArrayType,
6
6
  NamedType,
@@ -15,51 +15,44 @@ import { isPrimitiveTypeNode } from '@player-tools/xlr-utils';
15
15
  /**
16
16
  * Adds applicability and _comment properties to Assets
17
17
  */
18
- export const applyCommonProps: TransformFunction = (
19
- inputNode: NamedType | NodeType,
20
- capability: string
21
- ) => {
22
- const outputNode = { ...inputNode };
23
- if (capability === 'Assets') {
24
- if (outputNode.type === 'object') {
25
- if (!outputNode.properties.applicability) {
26
- outputNode.properties.applicability = {
27
- required: false,
28
- node: {
29
- type: 'or',
30
- name: 'Applicability',
31
- description:
32
- 'Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model',
33
- or: [
34
- {
35
- type: 'boolean',
36
- },
37
- {
38
- type: 'ref',
39
- ref: 'Expression',
40
- },
41
- ],
42
- },
43
- };
44
- }
18
+
19
+ export const applyCommonProps: TransformFunction = (node, capability) => {
20
+ return simpleTransformGenerator('object', ['Assets', 'Views'], (xlrNode) => {
21
+ if (!xlrNode.properties.applicability) {
22
+ // eslint-disable-next-line no-param-reassign
23
+ xlrNode.properties.applicability = {
24
+ required: false,
25
+ node: {
26
+ type: 'or',
27
+ name: 'Applicability',
28
+ description:
29
+ 'Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model',
30
+ or: [
31
+ {
32
+ type: 'boolean',
33
+ },
34
+ {
35
+ type: 'ref',
36
+ ref: 'Expression',
37
+ },
38
+ ],
39
+ },
40
+ };
45
41
  }
46
- }
47
42
 
48
- if (outputNode.type === 'object' && !outputNode.properties._comment) {
49
- outputNode.properties._comment = {
50
- required: false,
51
- node: {
52
- description: 'Adds a comment for the given node',
53
- type: 'string',
54
- },
55
- };
56
- } else if (outputNode.type === 'and') {
57
- outputNode.and.map((n) => applyCommonProps(n, capability));
58
- } else if (outputNode.type === 'or') {
59
- outputNode.or.map((n) => applyCommonProps(n, capability));
60
- }
43
+ if (!xlrNode.properties._comment) {
44
+ // eslint-disable-next-line no-param-reassign
45
+ xlrNode.properties._comment = {
46
+ required: false,
47
+ node: {
48
+ description: 'Adds a comment for the given node',
49
+ type: 'string',
50
+ },
51
+ };
52
+ }
61
53
 
62
- return outputNode;
54
+ return xlrNode;
55
+ })(node, capability);
63
56
  };
64
57
 
65
58
  /**
@@ -69,7 +62,7 @@ export const applyAssetWrapperOrSwitch: TransformFunction = (
69
62
  node,
70
63
  capability
71
64
  ) => {
72
- return simpleTransformGenerator('ref', 'Assets', (xlrNode) => {
65
+ return simpleTransformGenerator('ref', ['Assets', 'Views'], (xlrNode) => {
73
66
  if (xlrNode.ref.includes('AssetWrapper')) {
74
67
  return {
75
68
  ...xlrNode,
@@ -130,39 +123,43 @@ export const applyValueRefs: TransformFunction = (node, capability) => {
130
123
  * Computes possible template keys and adds them to an Asset
131
124
  */
132
125
  export const applyTemplateProperty: TransformFunction = (node, capability) => {
133
- const templateTypes: Array<RefType> = [];
134
- return simpleTransformGenerator('object', 'Assets', (inputNode) => {
135
- const xlrNode = { ...inputNode };
136
- for (const key in xlrNode.properties) {
137
- const value = xlrNode.properties[key];
138
- if (value.node.type === 'array') {
139
- value.required = false;
140
- templateTypes.push({
141
- type: 'ref',
142
- ref: `Template<${
143
- value.node.elementType.type === 'ref'
144
- ? value.node.elementType.ref
145
- : value.node.elementType.name
146
- }, "${key}">`,
147
- });
126
+ return simpleTransformGenerator(
127
+ 'object',
128
+ ['Assets', 'Views'],
129
+ (inputNode) => {
130
+ const templateTypes: Array<RefType> = [];
131
+ const xlrNode = { ...inputNode };
132
+ for (const key in xlrNode.properties) {
133
+ const value = xlrNode.properties[key];
134
+ if (value.node.type === 'array') {
135
+ value.required = false;
136
+ templateTypes.push({
137
+ type: 'ref',
138
+ ref: `Template<${
139
+ value.node.elementType.type === 'ref'
140
+ ? value.node.elementType.ref
141
+ : value.node.elementType.name
142
+ }, "${key}">`,
143
+ });
144
+ }
148
145
  }
149
- }
150
146
 
151
- if (templateTypes.length > 0) {
152
- const templateType: ArrayType = {
153
- type: 'array',
154
- elementType:
155
- templateTypes.length > 1
156
- ? { type: 'or', or: templateTypes }
157
- : templateTypes[0],
158
- description: 'A list of templates to process for this node',
159
- };
160
- xlrNode.properties.template = {
161
- required: false,
162
- node: templateType,
163
- };
164
- }
147
+ if (templateTypes.length > 0) {
148
+ const templateType: ArrayType = {
149
+ type: 'array',
150
+ elementType:
151
+ templateTypes.length > 1
152
+ ? { type: 'or', or: templateTypes }
153
+ : templateTypes[0],
154
+ description: 'A list of templates to process for this node',
155
+ };
156
+ xlrNode.properties.template = {
157
+ required: false,
158
+ node: templateType,
159
+ };
160
+ }
165
161
 
166
- return xlrNode;
167
- })(node, capability);
162
+ return xlrNode;
163
+ }
164
+ )(node, capability);
168
165
  };