MCPcopy
hub / github.com/pocketbase/pocketbase / jsSnapshotTemplate

Method jsSnapshotTemplate

plugins/migratecmd/templates.go:43–72  ·  view source on GitHub ↗
(collections []*core.Collection)

Source from the content-addressed store, hash-verified

41}
42
43func (p *plugin) jsSnapshotTemplate(collections []*core.Collection) (string, error) {
44 // unset timestamp fields
45 var collectionsData = make([]map[string]any, len(collections))
46 for i, c := range collections {
47 data, err := toMap(c)
48 if err != nil {
49 return "", fmt.Errorf("failed to serialize %q into a map: %w", c.Name, err)
50 }
51 delete(data, "created")
52 delete(data, "updated")
53 deleteNestedMapKey(data, "oauth2", "providers")
54 collectionsData[i] = data
55 }
56
57 jsonData, err := marhshalWithoutEscape(collectionsData, " ", " ")
58 if err != nil {
59 return "", fmt.Errorf("failed to serialize collections list: %w", err)
60 }
61
62 const template = jsTypesDirective + `migrate((app) => {
63 const snapshot = %s;
64
65 return app.importCollections(snapshot, false);
66}, (app) => {
67 return null;
68})
69`
70
71 return fmt.Sprintf(template, string(jsonData)), nil
72}
73
74func (p *plugin) jsCreateTemplate(collection *core.Collection) (string, error) {
75 // unset timestamp fields

Callers 1

Calls 3

toMapFunction · 0.85
deleteNestedMapKeyFunction · 0.85
marhshalWithoutEscapeFunction · 0.85

Tested by

no test coverage detected