@player-ui/make-flow 0.8.0--canary.307.9645 → 0.8.0-next.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.
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ function _define_property(obj, key, value) {
3
+ if (key in obj) {
4
+ Object.defineProperty(obj, key, {
5
+ value: value,
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true
9
+ });
10
+ } else {
11
+ obj[key] = value;
12
+ }
13
+ return obj;
14
+ }
15
+ function _object_spread(target) {
16
+ for(var i = 1; i < arguments.length; i++){
17
+ var source = arguments[i] != null ? arguments[i] : {};
18
+ var ownKeys = Object.keys(source);
19
+ if (typeof Object.getOwnPropertySymbols === "function") {
20
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
21
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
22
+ }));
23
+ }
24
+ ownKeys.forEach(function(key) {
25
+ _define_property(target, key, source[key]);
26
+ });
27
+ }
28
+ return target;
29
+ }
30
+ function ownKeys(object, enumerableOnly) {
31
+ var keys = Object.keys(object);
32
+ if (Object.getOwnPropertySymbols) {
33
+ var symbols = Object.getOwnPropertySymbols(object);
34
+ if (enumerableOnly) {
35
+ symbols = symbols.filter(function(sym) {
36
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
37
+ });
38
+ }
39
+ keys.push.apply(keys, symbols);
40
+ }
41
+ return keys;
42
+ }
43
+ function _object_spread_props(target, source) {
44
+ source = source != null ? source : {};
45
+ if (Object.getOwnPropertyDescriptors) {
46
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
47
+ } else {
48
+ ownKeys(Object(source)).forEach(function(key) {
49
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
50
+ });
51
+ }
52
+ return target;
53
+ }
54
+ var MakeFlow = function() {
55
+ var unwrapJSend = // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts
56
+ function unwrapJSend(obj) {
57
+ var isJSend = "status" in obj && "data" in obj;
58
+ if (isJSend) {
59
+ return obj.data;
60
+ }
61
+ return obj;
62
+ };
63
+ var __defProp = Object.defineProperty;
64
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
65
+ var __getOwnPropNames = Object.getOwnPropertyNames;
66
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
67
+ var __export = function(target, all) {
68
+ for(var name in all)__defProp(target, name, {
69
+ get: all[name],
70
+ enumerable: true
71
+ });
72
+ };
73
+ var __copyProps = function(to, from, except, desc) {
74
+ if (from && typeof from === "object" || typeof from === "function") {
75
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
76
+ try {
77
+ var _loop = function() {
78
+ var key = _step.value;
79
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
80
+ get: function() {
81
+ return from[key];
82
+ },
83
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
84
+ });
85
+ };
86
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
87
+ } catch (err) {
88
+ _didIteratorError = true;
89
+ _iteratorError = err;
90
+ } finally{
91
+ try {
92
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
93
+ _iterator.return();
94
+ }
95
+ } finally{
96
+ if (_didIteratorError) {
97
+ throw _iteratorError;
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return to;
103
+ };
104
+ var __toCommonJS = function(mod) {
105
+ return __copyProps(__defProp({}, "__esModule", {
106
+ value: true
107
+ }), mod);
108
+ };
109
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts
110
+ var src_exports = {};
111
+ __export(src_exports, {
112
+ ObjType: function() {
113
+ return ObjType;
114
+ },
115
+ identify: function() {
116
+ return identify;
117
+ },
118
+ makeFlow: function() {
119
+ return makeFlow;
120
+ }
121
+ });
122
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/identify.ts
123
+ var ObjType = /* @__PURE__ */ function(ObjType2) {
124
+ ObjType2[ObjType2["FLOW"] = 0] = "FLOW";
125
+ ObjType2[ObjType2["ASSET"] = 1] = "ASSET";
126
+ ObjType2[ObjType2["ASSET_WRAPPER"] = 2] = "ASSET_WRAPPER";
127
+ ObjType2[ObjType2["UNKNOWN"] = 3] = "UNKNOWN";
128
+ return ObjType2;
129
+ }(ObjType || {});
130
+ function identify(obj) {
131
+ if ("id" in obj && "type" in obj) {
132
+ return 1 /* ASSET */ ;
133
+ }
134
+ if ("asset" in obj && identify(obj.asset) === 1 /* ASSET */ ) {
135
+ return 2 /* ASSET_WRAPPER */ ;
136
+ }
137
+ if ("navigation" in obj || "schema" in obj || "views" in obj) {
138
+ return 0 /* FLOW */ ;
139
+ }
140
+ return 3 /* UNKNOWN */ ;
141
+ }
142
+ var createDefaultNav = function(flow, options) {
143
+ if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
144
+ var _flow_views__id, _options_outcome;
145
+ var navFlow = {
146
+ startState: "VIEW_0",
147
+ VIEW_0: {
148
+ state_type: "VIEW",
149
+ ref: (_flow_views__id = flow.views[0].id) !== null && _flow_views__id !== void 0 ? _flow_views__id : "".concat(flow.id, "-views-0"),
150
+ transitions: {
151
+ "*": "END_done",
152
+ Prev: "END_back"
153
+ }
154
+ },
155
+ END_done: {
156
+ state_type: "END",
157
+ outcome: (_options_outcome = options === null || options === void 0 ? void 0 : options.outcome) !== null && _options_outcome !== void 0 ? _options_outcome : "doneWithFlow"
158
+ },
159
+ END_back: {
160
+ state_type: "END",
161
+ outcome: "BACK"
162
+ }
163
+ };
164
+ if ((options === null || options === void 0 ? void 0 : options.onStart) !== void 0) {
165
+ navFlow.onStart = options.onStart;
166
+ }
167
+ if ((options === null || options === void 0 ? void 0 : options.onEnd) !== void 0) {
168
+ navFlow.onEnd = options.onEnd;
169
+ }
170
+ return _object_spread_props(_object_spread({}, flow), {
171
+ navigation: {
172
+ BEGIN: "Flow",
173
+ Flow: navFlow
174
+ }
175
+ });
176
+ }
177
+ return flow;
178
+ };
179
+ function makeFlow(obj, args) {
180
+ var objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj);
181
+ if (Array.isArray(objified)) {
182
+ var collection = {
183
+ id: "collection",
184
+ type: "collection",
185
+ values: objified.map(function(v) {
186
+ var type2 = identify(v);
187
+ if (type2 === 1 /* ASSET */ ) {
188
+ return {
189
+ asset: v
190
+ };
191
+ }
192
+ return v;
193
+ })
194
+ };
195
+ return makeFlow(collection);
196
+ }
197
+ var type = identify(obj);
198
+ if (type === 3 /* UNKNOWN */ ) {
199
+ throw new Error("No clue how to convert this into a flow. Just do it yourself");
200
+ }
201
+ if (type === 0 /* FLOW */ ) {
202
+ return createDefaultNav(obj, args);
203
+ }
204
+ if (type === 2 /* ASSET_WRAPPER */ ) {
205
+ return makeFlow(obj.asset);
206
+ }
207
+ return {
208
+ id: "generated-flow",
209
+ views: [
210
+ obj
211
+ ],
212
+ data: {},
213
+ navigation: {
214
+ BEGIN: "FLOW_1",
215
+ FLOW_1: {
216
+ startState: "VIEW_1",
217
+ VIEW_1: {
218
+ state_type: "VIEW",
219
+ ref: obj.id,
220
+ transitions: {
221
+ "*": "END_Done"
222
+ }
223
+ },
224
+ END_Done: {
225
+ state_type: "END",
226
+ outcome: "done"
227
+ }
228
+ }
229
+ }
230
+ };
231
+ }
232
+ return __toCommonJS(src_exports);
233
+ }();
234
+ //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/identify.ts"],"names":["ObjType","type"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AA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,GAAG;AAAA,QACH,YAAY;AAAA,UACV,OAAO;AAAA,UACP,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAKO,WAAS,SAAS,KAAU,MAAyB;AAC1D,UAAM,WAAW,YAAY,OAAO,QAAQ,WAAW,KAAK,MAAM,GAAG,IAAI,GAAG;AAE5E,QAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAM,aAA8B;AAAA,QAClC,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ,SAAS,IAAI,CAAC,MAAM;AAC1B,gBAAMC,QAAO,SAAS,CAAC;AAEvB,cAAIA,yBAAwB;AAC1B,mBAAO,EAAE,OAAO,EAAE;AAAA,UACpB;AAEA,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAEA,aAAO,SAAS,UAAU;AAAA,IAC5B;AAEA,UAAM,OAAO,SAAS,GAAG;AAEzB,QAAI,0BAA0B;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,QAAI,uBAAuB;AACzB,aAAO,iBAAiB,KAAK,IAAI;AAAA,IACnC;AAEA,QAAI,gCAAgC;AAClC,aAAO,SAAS,IAAI,KAAK;AAAA,IAC3B;AAEA,WAAO;AAAA,MACL,IAAI;AAAA,MACJ,OAAO,CAAC,GAAG;AAAA,MACX,MAAM,CAAC;AAAA,MACP,YAAY;AAAA,QACV,OAAO;AAAA,QACP,QAAQ;AAAA,UACN,YAAY;AAAA,UACZ,QAAQ;AAAA,YACN,YAAY;AAAA,YACZ,KAAK,IAAI;AAAA,YACT,aAAa;AAAA,cACX,KAAK;AAAA,YACP;AAAA,UACF;AAAA,UACA,UAAU;AAAA,YACR,YAAY;AAAA,YACZ,SAAS;AAAA,UACX;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF","sourcesContent":["import type {\n Flow,\n Asset,\n AssetWrapper,\n NavigationFlow,\n NavigationFlowEndState,\n} from \"@player-ui/types\";\nimport identify, { ObjType } from \"./identify\";\n\nexport * from \"./identify\";\nexport { identify };\n\ninterface JSend<T> {\n /** The status of the JSEND wrapper */\n status: string;\n /** The data we care about */\n data: T;\n}\n\ninterface CollectionAsset extends Asset<\"collection\"> {\n /** The values of the collection. Used when there are an array of assets passed to the makeFlow fn */\n values: Array<AssetWrapper>;\n}\n\n/** Check an object for the JSEND wrapper and remove it if needed */\nfunction unwrapJSend(obj: object) {\n const isJSend = \"status\" in obj && \"data\" in obj;\n\n if (isJSend) {\n return (obj as JSend<object>).data;\n }\n\n return obj;\n}\n\ninterface NavOptions {\n /** An optional expression to run when this Flow starts */\n onStart?: NavigationFlow[\"onStart\"];\n /** An optional expression to run when this Flow ends */\n onEnd?: NavigationFlow[\"onEnd\"];\n /**\n * A description of _how_ the flow ended.\n * If this is a flow started from another flow, the outcome determines the flow transition\n */\n outcome?: NavigationFlowEndState[\"outcome\"];\n}\n\n/**\n * create a default navigation if the flow was exactly one view and there is no navigation already\n */\nconst createDefaultNav = (flow: Flow, options?: NavOptions): Flow => {\n if (\n (flow.navigation === undefined || flow.navigation === null) &&\n Array.isArray(flow.views) &&\n flow.views.length === 1\n ) {\n const navFlow: NavigationFlow = {\n startState: \"VIEW_0\",\n VIEW_0: {\n state_type: \"VIEW\",\n ref: flow.views[0].id ?? `${flow.id}-views-0`,\n transitions: {\n \"*\": \"END_done\",\n Prev: \"END_back\",\n },\n },\n END_done: {\n state_type: \"END\",\n outcome: options?.outcome ?? \"doneWithFlow\",\n },\n END_back: {\n state_type: \"END\",\n outcome: \"BACK\",\n },\n };\n\n if (options?.onStart !== undefined) {\n navFlow.onStart = options.onStart;\n }\n\n if (options?.onEnd !== undefined) {\n navFlow.onEnd = options.onEnd;\n }\n\n return {\n ...flow,\n navigation: {\n BEGIN: \"Flow\",\n Flow: navFlow,\n },\n };\n }\n\n return flow;\n};\n\n/**\n * Take any given object and try to convert it to a flow\n */\nexport function makeFlow(obj: any, args?: NavOptions): Flow {\n const objified = unwrapJSend(typeof obj === \"string\" ? JSON.parse(obj) : obj);\n\n if (Array.isArray(objified)) {\n const collection: CollectionAsset = {\n id: \"collection\",\n type: \"collection\",\n values: objified.map((v) => {\n const type = identify(v);\n\n if (type === ObjType.ASSET) {\n return { asset: v };\n }\n\n return v;\n }),\n };\n\n return makeFlow(collection);\n }\n\n const type = identify(obj);\n\n if (type === ObjType.UNKNOWN) {\n throw new Error(\n \"No clue how to convert this into a flow. Just do it yourself\",\n );\n }\n\n if (type === ObjType.FLOW) {\n return createDefaultNav(obj, args);\n }\n\n if (type === ObjType.ASSET_WRAPPER) {\n return makeFlow(obj.asset);\n }\n\n return {\n id: \"generated-flow\",\n views: [obj],\n data: {},\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: obj.id,\n transitions: {\n \"*\": \"END_Done\",\n },\n },\n END_Done: {\n state_type: \"END\",\n outcome: \"done\",\n },\n },\n },\n };\n}\n","import type { AssetWrapper } from \"@player-ui/types\";\n\nexport enum ObjType {\n FLOW,\n ASSET,\n ASSET_WRAPPER,\n UNKNOWN,\n}\n\n/** Try to identify any object as an Asset or Flow */\nexport default function identify(obj: object): ObjType {\n if (\"id\" in obj && \"type\" in obj) {\n return ObjType.ASSET;\n }\n\n if (\n \"asset\" in obj &&\n identify((obj as AssetWrapper).asset) === ObjType.ASSET\n ) {\n return ObjType.ASSET_WRAPPER;\n }\n\n if (\"navigation\" in obj || \"schema\" in obj || \"views\" in obj) {\n return ObjType.FLOW;\n }\n\n return ObjType.UNKNOWN;\n}\n"]}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ObjType: () => ObjType,
24
+ identify: () => identify,
25
+ makeFlow: () => makeFlow
26
+ });
27
+ module.exports = __toCommonJS(src_exports);
28
+
29
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/identify.ts
30
+ var ObjType = /* @__PURE__ */ ((ObjType2) => {
31
+ ObjType2[ObjType2["FLOW"] = 0] = "FLOW";
32
+ ObjType2[ObjType2["ASSET"] = 1] = "ASSET";
33
+ ObjType2[ObjType2["ASSET_WRAPPER"] = 2] = "ASSET_WRAPPER";
34
+ ObjType2[ObjType2["UNKNOWN"] = 3] = "UNKNOWN";
35
+ return ObjType2;
36
+ })(ObjType || {});
37
+ function identify(obj) {
38
+ if ("id" in obj && "type" in obj) {
39
+ return 1 /* ASSET */;
40
+ }
41
+ if ("asset" in obj && identify(obj.asset) === 1 /* ASSET */) {
42
+ return 2 /* ASSET_WRAPPER */;
43
+ }
44
+ if ("navigation" in obj || "schema" in obj || "views" in obj) {
45
+ return 0 /* FLOW */;
46
+ }
47
+ return 3 /* UNKNOWN */;
48
+ }
49
+
50
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts
51
+ function unwrapJSend(obj) {
52
+ const isJSend = "status" in obj && "data" in obj;
53
+ if (isJSend) {
54
+ return obj.data;
55
+ }
56
+ return obj;
57
+ }
58
+ var createDefaultNav = (flow, options) => {
59
+ if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
60
+ const navFlow = {
61
+ startState: "VIEW_0",
62
+ VIEW_0: {
63
+ state_type: "VIEW",
64
+ ref: flow.views[0].id ?? `${flow.id}-views-0`,
65
+ transitions: {
66
+ "*": "END_done",
67
+ Prev: "END_back"
68
+ }
69
+ },
70
+ END_done: {
71
+ state_type: "END",
72
+ outcome: options?.outcome ?? "doneWithFlow"
73
+ },
74
+ END_back: {
75
+ state_type: "END",
76
+ outcome: "BACK"
77
+ }
78
+ };
79
+ if (options?.onStart !== void 0) {
80
+ navFlow.onStart = options.onStart;
81
+ }
82
+ if (options?.onEnd !== void 0) {
83
+ navFlow.onEnd = options.onEnd;
84
+ }
85
+ return {
86
+ ...flow,
87
+ navigation: {
88
+ BEGIN: "Flow",
89
+ Flow: navFlow
90
+ }
91
+ };
92
+ }
93
+ return flow;
94
+ };
95
+ function makeFlow(obj, args) {
96
+ const objified = unwrapJSend(typeof obj === "string" ? JSON.parse(obj) : obj);
97
+ if (Array.isArray(objified)) {
98
+ const collection = {
99
+ id: "collection",
100
+ type: "collection",
101
+ values: objified.map((v) => {
102
+ const type2 = identify(v);
103
+ if (type2 === 1 /* ASSET */) {
104
+ return { asset: v };
105
+ }
106
+ return v;
107
+ })
108
+ };
109
+ return makeFlow(collection);
110
+ }
111
+ const type = identify(obj);
112
+ if (type === 3 /* UNKNOWN */) {
113
+ throw new Error(
114
+ "No clue how to convert this into a flow. Just do it yourself"
115
+ );
116
+ }
117
+ if (type === 0 /* FLOW */) {
118
+ return createDefaultNav(obj, args);
119
+ }
120
+ if (type === 2 /* ASSET_WRAPPER */) {
121
+ return makeFlow(obj.asset);
122
+ }
123
+ return {
124
+ id: "generated-flow",
125
+ views: [obj],
126
+ data: {},
127
+ navigation: {
128
+ BEGIN: "FLOW_1",
129
+ FLOW_1: {
130
+ startState: "VIEW_1",
131
+ VIEW_1: {
132
+ state_type: "VIEW",
133
+ ref: obj.id,
134
+ transitions: {
135
+ "*": "END_Done"
136
+ }
137
+ },
138
+ END_Done: {
139
+ state_type: "END",
140
+ outcome: "done"
141
+ }
142
+ }
143
+ }
144
+ };
145
+ }
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ ObjType,
149
+ identify,
150
+ makeFlow
151
+ });
152
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/identify.ts"],"sourcesContent":["import type {\n Flow,\n Asset,\n AssetWrapper,\n NavigationFlow,\n NavigationFlowEndState,\n} from \"@player-ui/types\";\nimport identify, { ObjType } from \"./identify\";\n\nexport * from \"./identify\";\nexport { identify };\n\ninterface JSend<T> {\n /** The status of the JSEND wrapper */\n status: string;\n /** The data we care about */\n data: T;\n}\n\ninterface CollectionAsset extends Asset<\"collection\"> {\n /** The values of the collection. Used when there are an array of assets passed to the makeFlow fn */\n values: Array<AssetWrapper>;\n}\n\n/** Check an object for the JSEND wrapper and remove it if needed */\nfunction unwrapJSend(obj: object) {\n const isJSend = \"status\" in obj && \"data\" in obj;\n\n if (isJSend) {\n return (obj as JSend<object>).data;\n }\n\n return obj;\n}\n\ninterface NavOptions {\n /** An optional expression to run when this Flow starts */\n onStart?: NavigationFlow[\"onStart\"];\n /** An optional expression to run when this Flow ends */\n onEnd?: NavigationFlow[\"onEnd\"];\n /**\n * A description of _how_ the flow ended.\n * If this is a flow started from another flow, the outcome determines the flow transition\n */\n outcome?: NavigationFlowEndState[\"outcome\"];\n}\n\n/**\n * create a default navigation if the flow was exactly one view and there is no navigation already\n */\nconst createDefaultNav = (flow: Flow, options?: NavOptions): Flow => {\n if (\n (flow.navigation === undefined || flow.navigation === null) &&\n Array.isArray(flow.views) &&\n flow.views.length === 1\n ) {\n const navFlow: NavigationFlow = {\n startState: \"VIEW_0\",\n VIEW_0: {\n state_type: \"VIEW\",\n ref: flow.views[0].id ?? `${flow.id}-views-0`,\n transitions: {\n \"*\": \"END_done\",\n Prev: \"END_back\",\n },\n },\n END_done: {\n state_type: \"END\",\n outcome: options?.outcome ?? \"doneWithFlow\",\n },\n END_back: {\n state_type: \"END\",\n outcome: \"BACK\",\n },\n };\n\n if (options?.onStart !== undefined) {\n navFlow.onStart = options.onStart;\n }\n\n if (options?.onEnd !== undefined) {\n navFlow.onEnd = options.onEnd;\n }\n\n return {\n ...flow,\n navigation: {\n BEGIN: \"Flow\",\n Flow: navFlow,\n },\n };\n }\n\n return flow;\n};\n\n/**\n * Take any given object and try to convert it to a flow\n */\nexport function makeFlow(obj: any, args?: NavOptions): Flow {\n const objified = unwrapJSend(typeof obj === \"string\" ? JSON.parse(obj) : obj);\n\n if (Array.isArray(objified)) {\n const collection: CollectionAsset = {\n id: \"collection\",\n type: \"collection\",\n values: objified.map((v) => {\n const type = identify(v);\n\n if (type === ObjType.ASSET) {\n return { asset: v };\n }\n\n return v;\n }),\n };\n\n return makeFlow(collection);\n }\n\n const type = identify(obj);\n\n if (type === ObjType.UNKNOWN) {\n throw new Error(\n \"No clue how to convert this into a flow. Just do it yourself\",\n );\n }\n\n if (type === ObjType.FLOW) {\n return createDefaultNav(obj, args);\n }\n\n if (type === ObjType.ASSET_WRAPPER) {\n return makeFlow(obj.asset);\n }\n\n return {\n id: \"generated-flow\",\n views: [obj],\n data: {},\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: obj.id,\n transitions: {\n \"*\": \"END_Done\",\n },\n },\n END_Done: {\n state_type: \"END\",\n outcome: \"done\",\n },\n },\n },\n };\n}\n","import type { AssetWrapper } from \"@player-ui/types\";\n\nexport enum ObjType {\n FLOW,\n ASSET,\n ASSET_WRAPPER,\n UNKNOWN,\n}\n\n/** Try to identify any object as an Asset or Flow */\nexport default function identify(obj: object): ObjType {\n if (\"id\" in obj && \"type\" in obj) {\n return ObjType.ASSET;\n }\n\n if (\n \"asset\" in obj &&\n identify((obj as AssetWrapper).asset) === ObjType.ASSET\n ) {\n return ObjType.ASSET_WRAPPER;\n }\n\n if (\"navigation\" in obj || \"schema\" in obj || \"views\" in obj) {\n return ObjType.FLOW;\n }\n\n return ObjType.UNKNOWN;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAK,UAAL,kBAAKA,aAAL;AACL,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AACA,EAAAA,kBAAA;AAJU,SAAAA;AAAA,GAAA;AAQG,SAAR,SAA0B,KAAsB;AACrD,MAAI,QAAQ,OAAO,UAAU,KAAK;AAChC,WAAO;AAAA,EACT;AAEA,MACE,WAAW,OACX,SAAU,IAAqB,KAAK,MAAM,eAC1C;AACA,WAAO;AAAA,EACT;AAEA,MAAI,gBAAgB,OAAO,YAAY,OAAO,WAAW,KAAK;AAC5D,WAAO;AAAA,EACT;AAEA,SAAO;AACT;;;ADFA,SAAS,YAAY,KAAa;AAChC,QAAM,UAAU,YAAY,OAAO,UAAU;AAE7C,MAAI,SAAS;AACX,WAAQ,IAAsB;AAAA,EAChC;AAEA,SAAO;AACT;AAiBA,IAAM,mBAAmB,CAAC,MAAY,YAA+B;AACnE,OACG,KAAK,eAAe,UAAa,KAAK,eAAe,SACtD,MAAM,QAAQ,KAAK,KAAK,KACxB,KAAK,MAAM,WAAW,GACtB;AACA,UAAM,UAA0B;AAAA,MAC9B,YAAY;AAAA,MACZ,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,KAAK,KAAK,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;AAAA,QACnC,aAAa;AAAA,UACX,KAAK;AAAA,UACL,MAAM;AAAA,QACR;AAAA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AA,QACZ,QAAQ;AAAA,UACN,YAAY;AAAA,UACZ,KAAK,IAAI;AAAA,UACT,aAAa;AAAA,YACX,KAAK;AAAA,UACP;AAAA,QACF;AAAA,QACA,UAAU;AAAA,UACR,YAAY;AAAA,UACZ,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["ObjType","type"]}
@@ -1,42 +1,25 @@
1
- var ObjType;
2
- (function(ObjType2) {
1
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/identify.ts
2
+ var ObjType = /* @__PURE__ */ ((ObjType2) => {
3
3
  ObjType2[ObjType2["FLOW"] = 0] = "FLOW";
4
4
  ObjType2[ObjType2["ASSET"] = 1] = "ASSET";
5
5
  ObjType2[ObjType2["ASSET_WRAPPER"] = 2] = "ASSET_WRAPPER";
6
6
  ObjType2[ObjType2["UNKNOWN"] = 3] = "UNKNOWN";
7
- })(ObjType || (ObjType = {}));
7
+ return ObjType2;
8
+ })(ObjType || {});
8
9
  function identify(obj) {
9
10
  if ("id" in obj && "type" in obj) {
10
- return 1;
11
+ return 1 /* ASSET */;
11
12
  }
12
- if ("asset" in obj && identify(obj.asset) === 1) {
13
- return 2;
13
+ if ("asset" in obj && identify(obj.asset) === 1 /* ASSET */) {
14
+ return 2 /* ASSET_WRAPPER */;
14
15
  }
15
16
  if ("navigation" in obj || "schema" in obj || "views" in obj) {
16
- return 0;
17
+ return 0 /* FLOW */;
17
18
  }
18
- return 3;
19
+ return 3 /* UNKNOWN */;
19
20
  }
20
21
 
21
- var __defProp = Object.defineProperty;
22
- var __defProps = Object.defineProperties;
23
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
24
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
25
- var __hasOwnProp = Object.prototype.hasOwnProperty;
26
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
27
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
28
- var __spreadValues = (a, b) => {
29
- for (var prop in b || (b = {}))
30
- if (__hasOwnProp.call(b, prop))
31
- __defNormalProp(a, prop, b[prop]);
32
- if (__getOwnPropSymbols)
33
- for (var prop of __getOwnPropSymbols(b)) {
34
- if (__propIsEnum.call(b, prop))
35
- __defNormalProp(a, prop, b[prop]);
36
- }
37
- return a;
38
- };
39
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/make-flow/src/index.ts
40
23
  function unwrapJSend(obj) {
41
24
  const isJSend = "status" in obj && "data" in obj;
42
25
  if (isJSend) {
@@ -44,14 +27,13 @@ function unwrapJSend(obj) {
44
27
  }
45
28
  return obj;
46
29
  }
47
- const createDefaultNav = (flow, options) => {
48
- var _a, _b;
30
+ var createDefaultNav = (flow, options) => {
49
31
  if ((flow.navigation === void 0 || flow.navigation === null) && Array.isArray(flow.views) && flow.views.length === 1) {
50
32
  const navFlow = {
51
33
  startState: "VIEW_0",
52
34
  VIEW_0: {
53
35
  state_type: "VIEW",
54
- ref: (_a = flow.views[0].id) != null ? _a : `${flow.id}-views-0`,
36
+ ref: flow.views[0].id ?? `${flow.id}-views-0`,
55
37
  transitions: {
56
38
  "*": "END_done",
57
39
  Prev: "END_back"
@@ -59,25 +41,26 @@ const createDefaultNav = (flow, options) => {
59
41
  },
60
42
  END_done: {
61
43
  state_type: "END",
62
- outcome: (_b = options == null ? void 0 : options.outcome) != null ? _b : "doneWithFlow"
44
+ outcome: options?.outcome ?? "doneWithFlow"
63
45
  },
64
46
  END_back: {
65
47
  state_type: "END",
66
48
  outcome: "BACK"
67
49
  }
68
50
  };
69
- if ((options == null ? void 0 : options.onStart) !== void 0) {
51
+ if (options?.onStart !== void 0) {
70
52
  navFlow.onStart = options.onStart;
71
53
  }
72
- if ((options == null ? void 0 : options.onEnd) !== void 0) {
54
+ if (options?.onEnd !== void 0) {
73
55
  navFlow.onEnd = options.onEnd;
74
56
  }
75
- return __spreadProps(__spreadValues({}, flow), {
57
+ return {
58
+ ...flow,
76
59
  navigation: {
77
60
  BEGIN: "Flow",
78
61
  Flow: navFlow
79
62
  }
80
- });
63
+ };
81
64
  }
82
65
  return flow;
83
66
  };
@@ -89,7 +72,7 @@ function makeFlow(obj, args) {
89
72
  type: "collection",
90
73
  values: objified.map((v) => {
91
74
  const type2 = identify(v);
92
- if (type2 === ObjType.ASSET) {
75
+ if (type2 === 1 /* ASSET */) {
93
76
  return { asset: v };
94
77
  }
95
78
  return v;
@@ -98,13 +81,15 @@ function makeFlow(obj, args) {
98
81
  return makeFlow(collection);
99
82
  }
100
83
  const type = identify(obj);
101
- if (type === ObjType.UNKNOWN) {
102
- throw new Error("No clue how to convert this into a flow. Just do it yourself");
84
+ if (type === 3 /* UNKNOWN */) {
85
+ throw new Error(
86
+ "No clue how to convert this into a flow. Just do it yourself"
87
+ );
103
88
  }
104
- if (type === ObjType.FLOW) {
89
+ if (type === 0 /* FLOW */) {
105
90
  return createDefaultNav(obj, args);
106
91
  }
107
- if (type === ObjType.ASSET_WRAPPER) {
92
+ if (type === 2 /* ASSET_WRAPPER */) {
108
93
  return makeFlow(obj.asset);
109
94
  }
110
95
  return {
@@ -130,6 +115,9 @@ function makeFlow(obj, args) {
130
115
  }
131
116
  };
132
117
  }
133
-
134
- export { ObjType, identify, makeFlow };
135
- //# sourceMappingURL=index.esm.js.map
118
+ export {
119
+ ObjType,
120
+ identify,
121
+ makeFlow
122
+ };
123
+ //# sourceMappingURL=index.mjs.map