(collections []*core.Collection)
| 41 | } |
| 42 | |
| 43 | func (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 | |
| 74 | func (p *plugin) jsCreateTemplate(collection *core.Collection) (string, error) { |
| 75 | // unset timestamp fields |
no test coverage detected